Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use

sh -xv

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.

# ./

'@'' (using password: NO)user 'companycuser
share|improve this question
up vote 2 down vote accepted

Doesn't this work?

bash -x ./batchmaster_sh
share|improve this answer
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 2 '11 at 10:01
Well... what happens if you grep ./ or grep mysql ./ :) – Janne Pikkarainen Sep 2 '11 at 10:35

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

#!/bin/sh -x


#!/bin/bash -x

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

share|improve this answer
Thanks for your inputs. The problem got solved after running dos2unix command on the properties file. – shantanuo Sep 2 '11 at 10:18

There has been a debugger for bash around for a since the turn of the century. See

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.