- 论坛徽章:
- 60
|
回复 5# waker
不查不知道,一查原来还有这么一说的:
“在一般的linux系统当中(如redhat),使用sh调用执行脚本相当于打开了bash的POSIX标准模式(等效于bash的 --posix 参数),一般的,sh是bash的“子集”,不是子集的部分。bash程序执行,当“$0”是“sh”的时候,则要求代码遵循一定的规范,当不符合规范的语法存在时,则会报错,所以可以这样理解,“sh”并不是一个程序,而是一种标准(POSIX),这种标准,在一定程度上保证了脚本的跨系统性。”- [root@centos ~]# cat test.sh
- #!/bin/bash
- grep -wv -f <(echo '1 2 3 5 9'|sed 's/\s/\n/g') <(seq 1 10)
- [root@centos ~]#
- [root@centos ~]# sh test.sh
- test.sh: line 2: syntax error near unexpected token `('
- test.sh: line 2: `grep -wv -f <(echo '1 2 3 5 9'|sed 's/\s/\n/g') <(seq 1 10)'
- [root@centos ~]#
- [root@centos ~]# bash --posix test.sh
- test.sh: line 2: syntax error near unexpected token `('
- test.sh: line 2: `grep -wv -f <(echo '1 2 3 5 9'|sed 's/\s/\n/g') <(seq 1 10)'
- [root@centos ~]#
- [root@centos ~]# bash test.sh
- 4
- 6
- 7
- 8
- 10
- [root@centos ~]#
复制代码 |
|