I have a bash script
myscript.sh, which has a bunch of functions inside. To run one function, I would write
source myscript.sh; myfunction
How debug such a function?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You should also in Bash be able to use:
$ set -xT
which enables function trace and
$ set +xT
Also, with reference to another posted answer, I don't recommend using -v for debugging (verbose mode) unless you are checking a script/set of shell commands for syntax. One other (general) solution that is sometimes useful is making use of the
-n option in conjunction with
-x. This will "run" a script/commands without actually doing the last step of running a command. This can often let you pick up difficult errors in shell expansions and the like without causing unwanted mayhem.