runs a bash script in debugging mode

bash -x ./
Sample Output
bash -x ./ bash -x ./ 
+ COMMAND='bash -x ./'
+ echo 'command is bash -x ./'
command is bash -x ./
+ '[' 'bash -x ./' = '' ']'
++ dirname ./.c
++ basename ./.c
+ find . -name .c -mtime +1 -exec rm '{}' ';'
+ '[' '!' -f ./.c ']'
+ echo -n 'Enter commandlinefu username: '
Enter commandlinefu username: + read USERNAME

+ echo -n 'Enter commandlinefu password: '
Enter commandlinefu password: + read -s PASSWORD
+ echo

+ wget -O - --save-cookies ./.c --keep-session-cookies --post-data 'username=&password=&remember=on&submit=Let me in!'
+ echo -n 'Enter summary (required): '
Enter summary (required): + read SUMMARY
runs a bash script in debugging mode
++ echo runs a bash script in debugging mode
++ cut -c1-154
+ SUMMARY='runs a bash script in debugging mode'
++ echo bash -x ./
++ cut -c1-254
+ COMMAND='bash -x ./'
+ echo 'post-data is command=bash -x ./ a bash script in debugging mode&submit=Save'
post-data is command=bash -x ./ a bash script in debugging mode&submit=Save
+ wget -O - --load-cookies ./.c --post-data 'command=bash -x ./ a bash script in debugging mode&submit=Save&'
+ rm -f browse edit
+ rm -f '*17274*'

By: nottings
2009-02-25 19:10:21

3 Alternatives + Submit Alt

What Others Think

just running set -x first accomplishes the same thing or, add set -x within your script at the point you want to turn debugging on
nottings · 656 weeks and 4 days ago
Also debugging can be turned on at the top of the script when declaring the shell type: #!/bin/bash -x
hellspawn · 656 weeks and 4 days ago
thanks hellspawn! didn't know that, but it makes sense.
nottings · 656 weeks and 3 days ago
Thanks chaps. Made a lot of people at my place very happy.
mccalni · 654 weeks and 3 days ago
How is it debugging? Does is it just more verbose? It would be cool if there was a "safe-mode" where it blocks all writes to devices.
matthewbauer · 625 weeks and 4 days ago
see for tips for safer, more robust coding
nottings · 566 weeks and 4 days ago
Inside script "set -x" turns on debugging. "set +x" turns off debugging. Bash example: set -x; ls; ps; set +x
0xFF · 439 weeks and 1 day 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: