I am working with a terrible project. It uses a lot of messy shell script in background. Script might include some other scripts. And many error outputs were redirected to /dev/null. When a script is not executed successfully, I can use
echo $? to see the error code, but I am not able to know what command returned this error code.
These scripts are there. I do not want to review all code and add extra code to handle errors in a gentle way. Now I have two questions here:
- Is it possible to print the last bash command with arguments, that was not executed successfully?
- How to live with such messy shell script code?
bash -x /my/script
to print every line of the script as it is executed.
Can’t run the script like this? You can also add it to the shebang at the first line of the file.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.