我注意到當使用間接尋址(<
)時,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