Debug bash shell scripts.

bash -x SCRIPT
Display commands and their arguments as they are executed. Useful for debugging shell scripts.
Sample Output
+ start-stop-daemon -k 002 -S -p/var/run/ -c jetty -d /usr/share/jetty6 -b -m -a /usr/lib/jvm/java-1.5.0-sun/bin/java -- -DSTART=/usr/share/jetty6/etc/start.config -Xmx256m -Djava.awt.headless=true -DDEBUG -Djetty.port=8070 -Xms512m -Xmx2048m -XX:PermSize=384m -XX:MaxPermSize=512m -Djetty.home=/usr/share/jetty6 -jar /usr/share/jetty6/start.jar /etc/jetty6/jetty-logging.xml /etc/jetty6/jetty.xml
process already running.
+ exit 0

By: jcalvert
2009-03-13 00:09:07

3 Alternatives + Submit Alt

  • 26
    bash -x ./
    nottings · 2009-02-25 19:10:21 11

  • 4
    bash -x 2> log
    climatewarrior · 2009-06-08 19:31:51 1
  • Sends both stdout and stderr to the pipe which captures the data in the file 'out.test' and sends to stdout of tee (likely /dev/tty unless redirected). Works on Bourne, Korn and Bash shells.

    bash -x 2>&1 | tee out.test
    arcege · 2009-09-03 17:10:44 0

What Others Think

This can also be done by adding -x to the shebang (#!/bin/bash -x) of a script
x1101 · 699 weeks and 5 days ago
The most useful commands deserve to be submitted multiple times.
bwoodacre · 699 weeks and 5 days ago
Debugging today is as easy as pancake. Thanks for those who share their vast knowledge. frey | fence repair near me
freykarts · 67 weeks and 2 days ago
seofox · 37 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: