0

Possible Duplicate:
Error handling in BASH

I have one deployement script and i want to do exception handling in ubuntu shell script i.e. bash scripts. Is there any solution for this ?

0

1 Answer 1

0

I'm not certain what you mean by exception handling, but if you are looking for try and catch (or something similar) you are out of luck. There is set -e, but I wouldn't say that was even close. The nearest I can think of is the ERR signal trap (ERR is a fake signal)

For example;

trap 'echo [$LINENO] Error: $?' ERR

In this case we only display the line number and the return code, but you could place any code inside the quotes, including a function call. The definition of a failure is a non-zero $?. It is not executed for conditionals or arithmetic structures, and is not carried into functions.

The trap can be "switched off" with:

trap – ERR

See also the DEBUG fake signal.

Not the answer you're looking for? Browse other questions tagged or ask your own question.