Difference on bash and ash parentheses

1.8k views Asked by At

I was trying to use a diff command for comparing directory listings which works fine in bash:

diff  <(cd alpha ; find . -type f) <(cd beta; find . -type f)

However, on the ash (embedded device where no other shell is available) I get

-ash: syntax error: unexpected "("

Is there any difference regarding reading input operator < or parentheses ( )?

3

There are 3 answers

0
kojiro On BEST ANSWER

Don't confuse the angle bracket in <( … ) with the one in redirections like cat < file. In bash, <( echo hi ) is effectively a file with the contents "hi" (at least for reading purposes). So you can do

$ cat < <( echo hi )
hi

You can also do

$ echo <( : )
/dev/fd/63

And the shell actually expands that process substitution to a filename.

Process substitution is a bash feature. It is not part of the POSIX specification and does not exist in shells like ash. Redirection, on the other hand, is POSIX.

1
Etan Reisner On

The <(command) syntax is Process Substitution and is not supported by the ash shell (and other limited/etc. shells).

0
milkpirate On

I find this the most compact and comprehensible solution:

#!/bin/sh
diff /dev/fd/3 3<<-EOF /dev/fd/4 4<<-EOF
$(sort file1)
EOF
$(sort file2)
EOF

ref: https://unix.stackexchange.com/a/639752/137528