Debugging bash scripts.

Oliver Grawert ogra at ubuntu.com
Sat Feb 16 21:43:45 UTC 2019


hi,
Am Samstag, den 16.02.2019, 15:33 +0000 schrieb Ian Bruntlett:
> Hi,
> 
> I'm looking to have some kind of debugger to debug bash scripts.
> 
bash (or any POSIX capable shell too i think) comes with a bunch of
builtin debugging mechanisms ... add "set -ex" to the top of your
script ... thanks to the "x" you will get every step it does printed to
the console when you execute your script, "e" means to stop on errors. 

by adding that line to the script, the shell itself pretty much acts
like a debugger, showing you where execution fails and what is going on
etc ...

another good hint is to use the shellcheck (sudo apt install
shellcheck) command on all your scripts, this will help with quoting
errors and help you to improve your syntax in general by making useful
suggestions about your code.

ciao
	oli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20190216/10a91c2d/attachment.sig>


More information about the ubuntu-users mailing list