1

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?

user1801060
  • 2,733
  • 6
  • 25
  • 44

3 Answers3

4

Inside the script you can set flags for verbose, tracing and echoing to examine how the shell is interpreting your statements.

From bash beginner's guide

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.

Community
  • 1
  • 1
feihu
  • 1,935
  • 16
  • 24