Skip to content
Advertisement

Difference on bash and ash parentheses

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 ( )?

Advertisement

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.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement