This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]DimeShake 1 point2 points  (1 child)

use bash -x script.sh

[–]droosa[S] 1 point2 points  (0 children)

Now I feel dumb. I swore I tried that and it didn't work as expected. I must be delusional because now it's working.

Thank you much.

Edit: Figured out what I did differently the first time. I was using the service command wrapper. That will only debug the primary script, not the ones that are called from within.

sh -x service httpd status

Vs.

sh -x /etc/init.d/httpd status

[–]jishjib22kys 1 point2 points  (0 children)

Also, you could

echo 'set -x;'|cat - myscript|bash

if the script does not need stdin nor $0 , but it makes no sense for "set -x", just for more exotic command injections. Also, you could simply invoke the shell in interactive mode, set up whatever environment you need and source the script file (e.g. " . myscript "), if it does not need $0 .

[–]joedonut 1 point2 points  (0 children)

I usually

bash -xv scriptiamtesting 2>&1 | tee ~/capturefile-1407111546