Bash scripts are handy for putting a bunch of longer running jobs in one batch. In some occasions it can be useful to know which command is running at the moment, especially when the commands do not generate output themselves or this output is redirected to files.
Bash has a simple setting to achieve this:
set -x
which, according to help set, enables the following feature:
-x Print commands and their arguments as they are executed.
Disabling it just takes a mere
set +xYou can play with it from the bash command line itself, or put it in a bash script of course.
A simple illustration with this bash script put_out_the_trash.sh that contains silent commands:
#!/bin/bash set -x touch cookiewrap mv cookiewrap dustbin mv dustbin trashcan_kitchen mv trashcan_kitchen outside
Running the script from the command line gives you:
$ ./put_out_the_trash.sh + touch cookiewrap + mv cookiewrap dustbin + mv dustbin trashcan_kitchen + mv trashcan_kitchen outside $
So you see what's happening.
set -v is not exactly the same
set -v is not exactly the same: the difference is that -v just echos the command literally whereas -x allows all shell expansion and interpolation to take place and prints the command as it is actually executed.
set -v
set -v will do the exact same thing but not prefix every line with "+ "
Post new comment