I would like to trace a shell script for debugging purposes without having to modify its source code (e.g. change the shebang or insert a set -x at the beginning). It is a dpkg postinst script, so not actually called by myself on the shell.In hope of finding an environment variable for this I searched the man page for dash, but could not find anything.Is there some way to do this?
Can I trace a dash script without modifying its source code?
shell;shell script;dash
Since you have super user access, you can just change /bin/sh. Of course you'll be affecting anything that wants to use the default shell (for example, cron scripts), so try to restore it as soon as possible.First, create the wrapper. Create in your home directory a file named mysh with this content:#!/bin/dashexec /bin/dash -x $@Make it executable.$ chmod +x ~/myshThen change /bin/sh. First, make sure to note where it is pointing$ ls -l /bin/shlrwxrwxrwx 1 root root 9 Jan 12 17:42 /bin/sh -> /bin/dashThen, recklessly change it. (Warning: there will be a fraction of a microsecond when your system doesn't have /bin/sh.)$ sudo ln -sf ~/mysh /bin/shAs soon as you finish your thing, restore it.$ sudo ln -sf /bin/dash /bin/shGood luck!