Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/ 

script -qea /tmp/out.txt -c asdfl

if [ $? -eq 0 ]; then
    touch /tmp/RET0
    touch /tmp/RETNOT0

$ /tmp/ 
bash: asdfl: command not found
$ ls /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/

$ ls /tmp/RET0 

Can someone help me understand why this happens, and how I can get the correct return value?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.