问题遇到的现象和发生背景
偶然间发现了使用 sh 和 bash 来执行同一行命令,sh执行会语法错误,bash执行没有错;
上网查了一下发现 sh 是开启了POSIX标准的bash, /bin/sh 相当于 /bin/bash --posix,但是在Linux系统上 /bin/sh 只是指向 /bin/bash 的符号链接。求解下疑问:为啥么/bin/sh软链接能代表 /bin/bash --posix,软链接不应该只是快捷方式么,sh链接指向bash,--posix参数是如何指定的呢?
问题相关代码,请勿粘贴截图
[root@server1 shell_practice]# cat test.sh
grep 123 <(cat test.txt)
[root@server1 shell_practice]# cat test.txt
123456
abcdfg
[root@server1 shell_practice]# bash test.sh
123456
[root@server1 shell_practice]# sh test.sh
test.sh:行1: 未预期的符号 `(' 附近有语法错误
test.sh:行1: `grep 123 <(cat test.txt)'
[root@server1 shell_practice]# bash --posix test.sh
test.sh:行1: 未预期的符号 `(' 附近有语法错误
test.sh:行1: `grep 123 <(cat test.txt)'