2
我有一個csh腳本,需要使用newgrp進行部分運行。爲此,它遞歸地調用它自己。如何查看在newgrp中調用的命令的狀態?
#!/bin/csh
if ($1 == "") then
newgrp << ENDGRP
./newgrp_test.csh 2
if ($status != 0) then
echo "Second run fail"
exit 1
else
echo "Second run success"
exit 0
endif
ENDGRP
if ($status != 0) then
echo "Exiting failure"
exit 1
else
echo "Exiting success"
exit 0
endif
endif
if ($1 == "2") then
exit 1
endif
問題是我認爲它應該保證失敗,但我得到了成功的輸出。我的輸出如下所示:
Second run success
Exiting success
爲什麼我不能在newgrp中讀取腳本的狀態?
注意我找到了一個解決方法,通過刪除newgrp和ENDGRP之間的if塊,但我仍然好奇。