• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 688
  • Last Modified:

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!
0
megabyte78
Asked:
megabyte78
1 Solution
 
ahoffmannCommented:
your-command-producing-error-condition
if [ $? != 0 ]; then
  echo error occured
fi
0
 
megabyte78Author Commented:
just to confirm, can i do something like this?

if [ sqlplus -s /nolog != 0]; then
   echo error occured
fi
0
 
yuzhCommented:
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


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now