我注意到当使用间接寻址(<
)时,Solaris 10的Bourne shell,/bin/sh
(还有/sbin/sh
)会生成一个子shell。我已经尝试了一堆其他的Bourne十岁上下壳,其中包括:Solaris 10/bin/sh间接寻址
- 在Solaris 10上的POSIX
/usr/xpg4/bin/sh
外壳 /bin/bash
,/bin/ksh
在Solaris 10/bin/sh
在AIX 5/bin/sh
在Debian Linux上5
并且这些都没有表现出这种行为。
我很惊讶我以前没有被咬过。例如,在更稳健的壳(即,所有上面列出的那些)在以下脚本输出“1”:因为赋值x=1
所造成的间接子外壳发生
$ cat foo
#!/bin/sh
x=0
while read y ; do
x=1
done </etc/passwd
echo $x
$ ./foo
0
$
的Solaris 10的/bin/sh
返回0:当子外壳退出分配失败。 (如果我删除</etc/passwd
并从stdin
中读取,则按预期输出“1”)。
是否有一些古老的原因,“传统”Solaris sh
有这个属性?或者这是一个错误?
同时被视为命令? – Anders 2010-07-15 11:48:49
是的,下面是使用shell语法(可以在上面的链接文档中找到)的推导:'command - > compound_command - > while_clause' – 2010-07-15 13:12:03
Solaris 10和更早发行版中的'/ bin/sh'命令记录为不符合POSIX标准 - 对于符合POSIX标准,您需要使用'/ usr/xpg4/bin/sh'(实际上它基于ksh88而不是Bourne shell)。 – alanc 2010-07-15 14:50:04