[Toybox] Endless bash questions...

Rob Landley rob at landley.net
Sat Jun 4 16:12:37 PDT 2022


On 6/4/22 17:15, Chet Ramey wrote:
> On 6/4/22 6:08 PM, Rob Landley wrote:
>> Why does this work:
>> 
>> $ [[ $(cat) == "a b" ]] <<< "a b" > potato && rm potato && echo yes
>> yes
> 
> Here-strings are redirections, and a redirection may follow a compound
> command.
> 
>> But this is an error?
>> 
>> $ [[ $(cat) == "a b" ]] <(echo a b) > potato && rm potato && echo yes
>> bash: syntax error near unexpected token `<(echo a b)'
> 
> Process substitution is a word expansion, and so words consisting only of
> process substitutions are words, and words may not follow a compound
> command.

Ah! I knew that, but wasn't putting it together. Thanks.

$ [[ $(cat) == "a b" ]] < <(echo a b) && echo yes
yes

Rob

P.S. Currently I'm trying to work out the sequencing of redirects vs
$(subshells) because these work:

$ bash -c $'if true; then cat; fi << EOF\none two\nEOF'
one two
$ bash -c $'[[ $(cat) == "one two" ]] <<EOF\none two\nEOF'
$
$ bash -c $'[[ $(cat) == "one two" ]] <<EOF\none two\nEOF\n[ $? -eq 0 ] && echo yes'
yes

But this hangs (cat is reading stdin, not the HERE document):
$ bash -c $'[ $(cat) == "one two" ] <<EOF\none two\nEOF'
^C

Probably because [[ ]] is parsed as a flow control block and [ ] is just a
command. Order of operations on the command line doesn't seem to matter either:

$ << EOF [ $(cat) == one ]
> one
> EOF
^C

Possibly I need a gratuitous { } in my test to force ordering:

$ { [ $(cat) == abc ];} < <(echo abc) && echo yes
yes



More information about the Toybox mailing list