3

I use

sh -xv my_script.sh

to debug the /bin/sh script. How do I debug /bin/bash scripts?

I am getting the following error and I need to know the line that needs to edit.

# ./batch_master.sh

'@'10.10.10.10.' (using password: NO)user 'companycuser
shantanuo
  • 3,579
  • 8
  • 49
  • 66

3 Answers3

2

Doesn't this work?

bash -x ./batchmaster_sh
Janne Pikkarainen
  • 31,852
  • 4
  • 58
  • 81
  • It does work. But shows a lot of junk. I want to know only the mysql command that does not work. I do not see that anywhere in the output. The output is much lengthy than expected. – shantanuo Sep 02 '11 at 10:01
  • Well... what happens if you `grep 10.10.10.10 ./batch_master.sh` or `grep mysql ./batch_master.sh` :) – Janne Pikkarainen Sep 02 '11 at 10:35
1

Edit the script, add a -x option to the shell command line like:

#!/bin/sh -x

or

#!/bin/bash -x

It will print all executed commands and you can see what is done after what.

Notinlist
  • 217
  • 2
  • 10
1

There has been a debugger for bash around for a since the turn of the century. See http://bashdb.sourceforge.net/

If you are going to use set -x tracing I recommend setting PS4 to:

 PS4='(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]} -  [${SHLVL},${BASH_SUBSHELL}, $?]
'
rocky
  • 113
  • 5