Sample Header Ad - 728x90

How to print the failed command that caused the script's failure?

4 votes
2 answers
2395 views
I'm using the -e flag. Usage: #!/bin/bash -e Explained: -e Exit immediately if a simple command (see SHELL GRAMMAR above) exits with a non-zero status When a command in the script fails, the script exits and doesn't continue to execute the rest of the commands, which is exactly what I want. But, the failure contains just the info that the failed command chooses to disclose. Sometimes the failed command is very complicated, like a curl with many headers. **How do I print the failed command? I mean, immediately after it failed.** I know I can use the -x bash flag but it will print all of the executed commands. I'd like to see just the failed one.
Asked by AlikElzin-kilaka (571 rep)
Jan 23, 2023, 02:43 PM
Last activity: May 22, 2025, 05:07 PM