From a csh
script, I would like to open an xterm
and execute a command and then access the return value by saving it in a file.
xterm -e "MyCommand; echo $? > ./log.txt"
This does not work. $?
always returns 0
even if I replace MyCommand
with something that does not exit.
I know this question is very similar to this but it doesn't work for me. Perhaps because I am using csh here and -c
flag does not exist in my environment.
How can I access the return value of the command itself and not the xterm?
Use single-quotes to prevent your current shell from expanding symbols, e.g.,
xterm -e 'MyCommand; echo $? > ./log.txt'