How can I print each command before executing?
set -o xtrace
or
bash -x myscript.sh
This works with standard /bin/sh as well IIRC (it might be a POSIX thing then)
And remember, there is bashdb (bash Shell Debugger, release 4.0-0.4
)
To revert to normal, exit the subshell or
set +o xtrace
set -x
is fine, but if you do something like:
set -x;
command;
set +x;
it would result in printing
+ command
+ set +x;
You can use a subshell to prevent that such as:
(set -x; command)
which would just print the command.