How to get the exit code of a command, not xterm?

If I call a command (in my case another script) with xterm as follows:

xterm -e sh second.sh 

Value in $? after returning xterm is the xterm exit status code (usually 0 for me), not my script.

Anyway, to get the exit status code of my script?

+6
source share
1 answer

You can do something like this:

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

The exit status of yourcommand now in the status variable.

+5
source

Source: https://habr.com/ru/post/903294/


All Articles