parsed.org

Tips by tag: logic

Halting a Script After Command Failure by cygnus on Dec 12, 2005 10:59 AM

A shell script which runs a sequence of commands will run them all even if some of them fail. This is rarely desirable, as later commands will usually depend on the success of prior ones.

You can use && between commands to implement this dependency, of course, or you can use the -e switch on the shebang line (works with bash, may work with other shells) to cause the interpreter to halt execution after any command returns a non-zero exit code:

#!/.../bash -e
bashhaltlogicoperatorsshell
RSS