Debugging bash scripts.

Ralf Mardorf silver.bullet at zoho.com
Sat Feb 16 16:33:16 UTC 2019


PS:

Possible correct syntax, but bad typos could be work around by
"interactive" options, e.g.

It should read

  sudo rm -r /tmp/foo

but regarding a typo it's

  sudo rm -r / tmp/foo

to avoid serious trouble

  sudo rm -Ir /tmp/foo

does the trick, even with a typo

  sudo rm -Ir / tmp/foo

isn't executed without interaction.

  mv -i foo bar

even doesn't require interaction, as long as "bar" doesn't exist.

If your bash scripts really need debugging that much, you not only
should consider to use a debugger, but also to run them in a sandboxed
environment (chroot, systemd-nspawn, virtual machine or fake-whatsoever
"development" container/install). Running the script without a debugger
anyway displays syntax errors:

[rocketmouse at archlinux tmp]$ cat test.bash 
#!/bin/bash

pups

exit
[rocketmouse at archlinux tmp]$ bash -n test.bash 
[rocketmouse at archlinux tmp]$ bash test.bash 
test.bash: line 3: pups: command not found

Btw. my apologies, "--debugger" requires bashdb:

[rocketmouse at archlinux tmp]$ bash --debugger test.bash 
test.bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
test.bash: warning: cannot start debugger; debugging mode disabled
test.bash: line 3: pups: command not found





More information about the ubuntu-users mailing list