3

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?

7

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.

  • In man bash it’s under SHELL BUILTIN COMMANDS/set: “After expanding each simple command, for command, case command, select command, or arithmetic for command, display the expanded value of PS4, followed by the command and its expanded arguments or associated word list.” – dessert Aug 23 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.