iwekesi iwekesi - 10 months ago 45
Bash Question

use of flags in bash script

Scripts in linux start with some declaration like :


Correct me if I am wrong : this probably says which shell to use.

I have also seen some scripts which say :

#!/bin/bash -ex

what is the use of the flags -ex

#!/bin/bash -ex


set -e -x

Man Page (http://ss64.com/bash/set.html):

-e  Exit immediately if a simple command exits with a non-zero status, unless
   the command that fails is part of an until or  while loop, part of an
   if statement, part of a && or || list, or if the command's return status
   is being inverted using !.  -o errexit

-x  Print a trace of simple commands and their arguments
   after they are expanded and before they are executed. -o xtrace