I'm running a bash script on cygwin. The script fails and I'd love to know the state of some enviroment variables in the script. Is there any way to trace the execution of a bash script?
Asked
Active
Viewed 1,559 times
3 Answers
4
Inside the script you can set flags for verbose, tracing and echoing to examine how the shell is interpreting your statements.
set -x # expand variables
set +x # turn it off
set -v # set verbose
set +v # turn it off
See also: http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

vwvan
- 417
- 1
- 4
- 12
1
You can use trap
to call env
to dump the environment before the script exits.
There are many examples of using trap
to ensure that temporary files are deleted on exit, which you can easily modify.

Emmet
- 6,192
- 26
- 39
1
Please take a look at the answer here.
sh -x script [arg1 ...]
bash -x script [arg1 ...]
And here is a great post about HowTo: Debug a Shell Script Under Linux or UNIX. I think this would be helpful.