Another option that you might want to consider using is -v. The -x option is not the only debugging option. If you don't want to concern yourself with adding and later removing the -x from the shebang lines in your scripts, you can pass it as an argument to the shell instead like so: Imagine one of your less technical users staring at several dozen lines of output when expecting only a single line of output. One of the annoyances associated with using the -x within the shebang line is that you can easily forget to remove it after you have found and fixed the script's problem. By interpreting each of your arguments before displaying each command being run, this debugging option allows you to see what the script is actually working on. + /usr/lib/sendmail 'map server is down' shows us which file the script is looking for, what command is being run, what message is being sent and who should be receiving the message that is being sent. In the heavily parameterized syntax shown above, for example, the addition of -x might show us this: If you're not sure how a particular variable is being resolved at a critical point in your script, this option will show you.
If you don't know, for example, exactly where a script is failing, use of this option should show you very clearly what commands were being executed when the script failed and what data they were using. The -x option prints commands and arguments as they are executed. One of the ways that you can get more information on script failures is to use the -x argument in your shebang line, like this:
You don't want to know, after all, just that a file wasn't found or a command failed you want to know what file the script was looking for or which portion of the command syntax caused the failure.
#Cmud script debugger code
While this kind of code may be very reusable, it's also very hard to read. In a script where nearly every line contains variable names, it's hard to figure out what is actually going on. I've worked with scripts, for example, with commands that look like this: The error messages that are displayed when a script malfunctions range from effective to practically useless - especially when the scripts themselves are long, complicated and heavily parameterized.