[Toybox] Would someone please explain what bash is doing here?
Rob Landley
rob at landley.net
Mon Mar 16 05:54:39 PDT 2020
On 3/13/20 1:45 PM, Chet Ramey wrote:
> On 3/13/20 12:27 PM, enh wrote:
>
>>> The dash folks would say so.
>>
>> except now you need two shells :-)
>
> Well, that's their bed. I would say you only need one, of course.
Next question: what's the deal with "echo $(<input)"?
$ echo potato > input
$ echo $(<input)
potato
$ echo $( <input)
potato
$ echo $(X=Y <input)
$ echo $(<input X=Y)
$ echo $(<input >&2)
$ echo $(exec <input)
$ echo $(<>input)
$ cat <(<input)
$ cat input
potato
This is a special-case hack, isn't it?
Next question: what does \ mean in backticks?
$ echo `X=y; echo $X`
y
$ echo `X=y; echo \$X`
y
$ echo `X=y; echo \\$X`
$X
$ echo `X=y; echo \`$X`
bash: command substitution: line 1: unexpected EOF looking for matching ``'
bash: command substitution: line 2: syntax error: unexpected end of file
$ echo $(X=y; echo \$X)
$X
A single backslash gets eaten, so you need two, which is not how $() works. But
you can't escape a backtick? What's it _doing_? (The defective annoying shell
does the same thing so I'm sure posix is to blame somehow, but what's the
REASONING? I'd try to look it up if posix's shell stuff had any sort of
organization short of "read the whole thing cover to cover and spot where they
hid it _this_ time...)
Rob
More information about the Toybox
mailing list