Simon Wistow (deflatermouse) wrote,
Simon Wistow
deflatermouse

exit codes in bash

Spot what's wrong with this shell script

    ./somecommand
    if [ $? -ne 0 ]; then
        exit $?
    fi

Got it? It will always exit with a code of 0 because the if statement is actually a command. Doh.

Tags: doh, exit, shell script
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments