Hi,
how can one turn off the error messages of a bash script?
I want to turn it off, and handle the expected ones by myself
For instance, when it does not find some files, to show my specific error message.
Thanks
Hi,
how can one turn off the error messages of a bash script?
I want to turn it off, and handle the expected ones by myself
For instance, when it does not find some files, to show my specific error message.
Thanks
You can for sure "trap" them by redirecting stderr to somewhere else.
Not sure you can replace them with "your own" without checking for various return codes and handling this on a case by case basis, though.
You don't want to turn them off - you want to capture them and parse them so you can show your own message. (Though if the script is well-written, you don't actually have to capture them, just check the exit code.) You'll need to redirect stderr
script_to_run 2> captured_stderr
# now examine the contents of captured_stderr
If you can do it just with the exit code, you can redirect to /dev/null
instead.
For more about redirection, try the short version or long version here.