PDA

View Full Version : [SOLVED] Error messages for the unknown - bash



whatthefunk
September 17th, 2011, 09:06 AM
My bash scripts contain error messages for errors which I think might occur, but sometimes something happens that I did not expect. I would like to have a generic error message for these times. How do I write this into my scripts?

hakermania
September 17th, 2011, 01:57 PM
Hm, an idea is to send all stderr to /dev/null and in every command to check the return code. If it's an error code, run a function which contains your generic error message.
It might be a better way.

karlson
September 17th, 2011, 04:54 PM
My bash scripts contain error messages for errors which I think might occur, but sometimes something happens that I did not expect. I would like to have a generic error message for these times. How do I write this into my scripts?

In general it's a *) in the case statement. If you are using ifs then it's the last else case.

whatthefunk
September 18th, 2011, 04:27 AM
In general it's a *) in the case statement. If you are using ifs then it's the last else case.

Perfect. I dont know why I didnt think of this before... Thanks for replying, both of you.