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 (
)
?
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.
<(command)
语法是Process Substitution,并且ash
shell(和其他受限制的/ etc。shell)不支持。
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.