Search code examples
shellunixscripting

What does `set -x` do?


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

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

Solution

  • set -x enables a shell mode where all executed commands are printed to the terminal.

    In your case it's used for debugging, which is a typical use case for set -x: printing every command as it is executed may help you visualize the script's control flow if it is not functioning as expected.

    set +x disables it.