如果我使用xterm这样的命令(在我的情况下是另一个脚本)进行调用:
xterm -e sh second.sh
< p > 在 xterm 返回后,$?
中的值是 xterm 的退出状态码(通常为 0),而不是我的脚本。< /p >
< p > 有没有办法获取我的脚本的退出状态码?< /p >
xterm
直接报告命令的状态。 - Fred Fooecho $? > '$statusfile
?重定向(>)是sh
的一部分,要重定向的文件并没有在那里写,而是作为 xterm 的一部分? - Zvika$statusfile
包含临时文件的文件名,shell 需要在将其作为 xterm 的-c
参数的一部分之前进行扩展。请注意,'
和$statusfile
之间没有空格,这意味着 shell 将扩展的$statusfile
连接到'yourcommand; echo $? > '
。此外,我会写成"$statusfile"
,以防止 shell 解释$statusfile
中的任何内容。另一种编写方式是:"yourcommand; echo \$? > $statusfile"
或更好的方式是"yourcommand; echo \$? > '$statusfile'"
。 - Bodo Thiesen