Groups > Unix Linux > Linux > Re: Capturing program return codes in a bash script?




Re: Capturing program return codes in a bash script?

Re: Capturing program return codes in a bash script?
Wed, 02 Apr 2008 21:33:13 GMT
Ivan Marsh <annoyed@you.now> writes:


>How do I determine if an command completed successfully when run from a
>bash script to decide what the script should do next?

>Working on a mysqldump backup script which works pretty nice... but
>doesn't really care whether the database dump dies, errors out or
>completes successfully.

$?
is the return code of the last command run.

command1 && command2
executes command2 only if command1 completes suddessfully

if command; then
  command1
     .
     .
else
  command2
    .
    .
fi
will execute command1 . .  if command completes successfully and command2 . . 
 if it does not.

Those should be enought to get started with.

man bash



>I figure that's kind of important for a backup script.

>-- 
>"Remain calm, we're here to protect you!"
Post Reply
about | contact