Reputation: 35
I was wondering if it is possible to remove the error messages from bash. So for example, a bash script take a users input and if it runs properly in the terminal it doesn't return anything (it just runs the command), but if it fails, then it removes the error message and runs another script. Initially I thought this would be possible using \e[K, but that won't work I don't think. || doesn't work either as it still returns the error message before running the secondary command. Is there any way I can do this.
Thanks Ben
Upvotes: 2
Views: 4873
Reputation: 123648
You could say:
bash script1 2>/dev/null || bash script2
This would redirect STDERR
of script1 to /dev/null
and execute script2
if the former exited with a non-zero status code.
Upvotes: 3