What does this mean?
h2t=$((exec 2>&-; (which lynx >/dev/null && echo lynx -stdin -dump) \
|| which html2text || which cat) |tail -n 1)
Ok, h2t=...
means it's setting a variable.
I thought double-parens were for arithmetic operations. If that's the case I don't see any arithmetic there, and I'm thoroughly baffled.
Of course, there is a 15-line comment block above that line of code, which explains the intent. Unfortunately the comment is in unicode version of ancient sumerian, and I cannot interpret it.
**Only kidding! There is no comment.
Addendum: This is from https://github.com/micha/resty/blob/master/resty
twalberg in a comment to my answer spotted it. Turns out the outer
$()
assigns a command line, depending on the availability of various tools that might be able to convert HTML to text.Therefore
h2t
contains either thelynx -stdin -dump
command line, or failing that (i.e.lynx
not available),html2text
or as a last resortcat
. The commands for the latter two come from thewhich
invocations, the one for the former from theecho
.It converts HTML to text from stdin.
Let's split it up.
exec 2>&-
sets up a redirect in the subshell (shuts upstderr
, IIRC)stdin
.||
make not much sense because they only evaluate whetherhtml2text
andcat
are installed, but don't run themScratch that. Since it's an
echo
it doesn't do anything. Looks like prototyping to me.Taking it apart to make more readable: