I have a shell script which uses process substitution
The script is:
#!/bin/bash while read line do echo "$line" done < <( grep "^abcd$" file.txt ) When I run the script using sh file.sh I get the following output
$sh file.sh file.sh: line 5: syntax error near unexpected token `<' file.sh: line 5: `done < <( grep "^abcd$" file.txt )' When I run the script using bash file.sh, the script works.
Interestingly, sh is a soft-link mapped to /bin/bash.
$ which bash /bin/bash $ which sh /usr/bin/sh $ ls -l /usr/bin/sh lrwxrwxrwx 1 root root 9 Jul 23 2012 /usr/bin/sh -> /bin/bash $ ls -l /bin/bash -rwxr-xr-x 1 root root 648016 Jul 12 2012 /bin/bash I tested to make sure symbolic links are being followed in my shell using the following:
$ ./a.out hello world $ ln -s a.out a.link $ ./a.link hello world $ ls -l a.out -rwx--x--x 1 xxxx xxxx 16614 Dec 27 19:53 a.out $ ls -l a.link lrwxrwxrwx 1 xxxx xxxx 5 May 14 14:12 a.link -> a.out I am unable to understand why sh file.sh does not execute as /bin/bash file.sh since sh is a symbolic link to /bin/bash.
Any insights will be much appreciated. Thanks.
/bincomes before/usr/binin$PATHand there is ashprogram in/bin.which shshows/bin/shwhich points to/bin/bash...thus should not be/bin/bashbe executed? Thanksbashis executed, but it detects that it is started using the nameshand behaves accordingly: as a (nearly) strictly compliant POSIX shell. One consequence of that is that it does not recognize process substitutions.bashis executed assh, it enters inPOSIXmode...and does not run in normalbashmode. So if I execute asbash --posix file.sh, I get the same error. Thanks for your time.