如何获取命令的退出代码而不是xterm?

nei*_*man 7 bash xterm

如果我用xterm调用一个命令(在我的情况下是另一个脚本),如下所示:

xterm -e sh second.sh
Run Code Online (Sandbox Code Playgroud)

$?xterm返回后的值是xterm的退出状态代码(通常为我0)而不是我的脚本.

反正有没有得到我的脚本的退出状态代码?

Sta*_*ven 5

You could do something like this:

statusfile=$(mktemp)
xterm -e sh -c 'yourcommand; echo $? > '$statusfile
status=$(cat $statusfile)
rm $statusfile
Run Code Online (Sandbox Code Playgroud)

The exit status of yourcommand is now in variable status.

  • +1.似乎没有办法让`xterm`直接报告命令的状态. (2认同)