What does "set -x" do in a bash script?

I am reading a bash script and it start with set -x. I googled around and I did not find any single manual which does describe all the flags in details specially -x.

My apologies if I sound like someone who did not do his research before asking the question here but I sincerely did not find any information on set -x. Any ideas?


As help set says:

      -x  Print commands and their arguments as they are executed.

It works both in interactive and non-interactive shells, so you can try running set -x in an interactive shell to see the effect. Each command that is run is echoed to you first (with + signs in front of them to help you distinguish them from most regular output).

ek@Cord:~$ echo hello world
+ echo hello world
hello world

(If you see way more output than you expect an an interactive shell, your shell may be running commands to build your prompt. For example, you'll see about twenty additional lines if your prompt is set up to show information about the git repository you're navigated to, even if you're not actually in a repo now.)

To turn it off run set +x. Somewhat confusingly, with set, - enables a shell option and + disables it.

For more information, see 4.3.1 The Set Builtin in the Bash reference manual.