I have a shellscript I want to run via at and use script to capture a transcript. script -e was introduced in util-linux-ng 2.18 and returns the retval of the child process.
I want to capture the return value of the command I execute through script, and react accordingly.
$ cat /tmp/b.sh #!/bin/bash script -qea /tmp/out.txt -c asdfl if [ $? -eq 0 ]; then touch /tmp/RET0 else touch /tmp/RETNOT0 fi $ /tmp/b.sh bash: asdfl: command not found $ ls /tmp/RETNOT0 /tmp/RETNOT0
I expect the outcome above because "asdf1" isn't a valid command.
However, if I run the same shell script through at or crontab, the return value is zero.
$ crontab -l 40 17 * * * /tmp/b.sh $ ls /tmp/RET0 /tmp/RET0
Can someone help me understand why this happens, and how I can get the correct return value?