Link to home
Start Free TrialLog in
Avatar of megabyte78
megabyte78

asked on

how to handle error in bash scripting in unix

hi,

How do i handle an error if for example, i cannot connect to database in bash scripting in unix.

pls help!
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of megabyte78
megabyte78

ASKER

just to confirm, can i do something like this?

if [ sqlplus -s /nolog != 0]; then
   echo error occured
fi
Avatar of yuzh
what ahoffmann mean is:

sqlplus -s /nolog
if [ $? -ne 0 ] ; then
  echo error occured
fi
# $? is the return value of your last command

you can do something like the following:

if sqlplus -s /nolog ; then
   echo "ok !"
else
   echo "error occured"
fi