I'm having some problems with some scripts in bash, about errors and unexpected behaviors. I would like to investigate the causes of the problems so I can apply fixes. Is there a way I can turn some kind of "debug-mode" for bash, to get more information?
Start your bash script with Additional with If you want to write the debug output to a separate file, add this to your script:
See: http://stackoverflow.com/a/25593226/3776858 If you want to see line numbers add this:
|
|||||
|
The standard method to debug scripts in most Bourne-based shells, like bash is to write
this is useful for either, the interpreter or inside scripts. For example:
In the above we can see why find is failing due some single quotes. To deactivate the feature, just type |
||||
|
Using
|
|
On Ubuntu, I have
alias say="spd-say" in my .bashrc, which imitates the say command from other distros or OS X.
–
Doorknob
Sep 16 '14 at 3:41
|
There's a bash debugger, bashdb, which is an installable package on many distros. It uses bash's built-in extended debugging mode (
As in gdb, the statement is shown just before it is about to be executed. So we can examine variables to see what the statement will do before it does it.
That's not what we want! Let's look at the parameter expansion again.
OK, that works. Let's set
Looks good. Continue the script.
|
|||||
|
Using EclipseYou can use the combined environment of Eclipse and Shelled with the "_DEBUG.sh" script linked below.
Switching shellsBy default the Shelled development tool uses NOTE: You can change this by going to: Window -> Preference -> Shell Script -> Interpreters Setup InstructionsThe Debugger package has the steps for using the
The bash debug UIThis bash debugger has the full features of standard programming debuggers such as:
The Shelled (Shell Script Editor) IDE (Integrated Development Environment) has an added bonus of performing context checking, highlighting and indenting while writing your script. If it doesn't indent correctly, you might immediately be able to flag/local many errors there. Then there are other IDE benefits such as:
|
|||||
|
simply use:
the same for shell:
|
|||
|