What does `set -x` do?

Ole picture Ole · Mar 29, 2016 · Viewed 195.2k times · Source

I have a shell script with the following line in it:

[ "$DEBUG" == 'true' ] && set -x

Answer

John Zwinck picture John Zwinck · Mar 29, 2016

set -x enables a mode of the shell where all executed commands are printed to the terminal. In your case it's clearly used for debugging, which is a typical use case for set -x: printing every command as it is executed may help you to visualize the control flow of the script if it is not functioning as expected.

set +x disables it.