difference between sh and bash when symlink is used -


i have shell script uses process substitution

the script is:

  #!/bin/bash   while read line       echo "$line"   done < <( grep "^abcd$" file.txt ) 

when run script using sh file.sh following output

$sh file.sh file.sh: line 5: syntax error near unexpected token `<' file.sh: line 5: `done < <( grep "^abcd$" file.txt )' 

when run script using bash file.sh, script works.

interestingly, sh soft-link mapped /bin/bash.

$ bash /bin/bash $ 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 make sure symbolic links being followed in shell using 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 unable understand why sh file.sh not execute /bin/bash file.sh since sh symbolic link /bin/bash.

any insights appreciated. thanks.

when invoked sh, bash enters posix mode after startup files read. process substitution not recognized in posix mode. according posix, <(foo) should direct input file named (foo). (well, is, according reading of standard. grammar ambiguous in many places.)

edit: bash manual:

the following list what’s changed when ‘posix mode’ in effect: ... process substitution not available. 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -