103

I typed set -x in terminal.

Now the terminal keeps printing the last command run on top of my output so the command

~]$echo "this is what I see"

returns

+ echo 'this is what I see'
this is what I see

There is no man page for set, how do I turn set -x off?

terdon
  • 234,489
  • 66
  • 447
  • 667
lonewarrior556
  • 2,033
  • 4
  • 16
  • 13
  • 8
    `set` is a shell `builtin` command (at least in bash it is), so the documentation is found in bash's man page. Search the man page for `/^ *SHELL BUILTIN COMMANDS` to read all about `set` and its friends! – dg99 Aug 07 '14 at 19:25
  • 4
    but *there is* a `man` page for `set`! It is part of the POSIX programmers guide... You should *really* get that series... please? – mikeserv Aug 07 '14 at 20:55
  • 9
    In Bash, type `help set`. – 200_success Aug 07 '14 at 22:28
  • @lonewarrior556 if you find any of the answer helpful, can you please comment and/or mark a solution. We contribute our time to assist.... – Simply_Me Aug 08 '14 at 20:39

4 Answers4

107

Use set +x. More information:

$ type set
set is a special shell builtin

Since set is a shell builtin, it is documented in the documentation of your shell.

Beware that some systems have man pages for shell builtins, but these man pages are only correct if you're using the default shell. On Linux, you may have man pages that present POSIX commands, which will turn up for shell builtins because there's no man page of a standalone utility to shadow them; these man pages are correct for all Bourne-style shells (dash, bash, *ksh, and even zsh) but typically incomplete.

See Reading and searching long man pages for tips on searching for a builtin in a long shell man page.

In this case, the answer is the same for all Bourne-style shells. If set -LETTER turns on an option, set +LETTER turns it off. Thus, set +x turns off traces.

The last trace, for the set +x command itself, is not completely avoidable. You can suppress it with { set +x; } 2>/dev/null, but in some shells there's still a trace for the redirection itself. You can avoid a trace for set +x by not running it and instead letting the (sub)shell exit: if it's ok to run the traced command(s) in a subshell, you can use(set -x; command to trace; other command to trace); command that is not traced.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 6
    `{ set +x ;} 2> /dev/null` hides the `set +x` trace (won't work in the Bourne shell though). Some shells still output a `+ 2> /dev/null` though. – Stéphane Chazelas Sep 30 '16 at 06:24
  • @GeroldBroser see [Inline debug (xtrace) in scripts](//unix.stackexchange.com/a/253505) --- [bash: escape individual lines from \`-x\` echoing](//unix.stackexchange.com/a/60049) --- [Suppress the bash execution trace (set -x) from the outside of the script](//unix.stackexchange.com/a/352101) – Stéphane Chazelas Jul 14 '22 at 11:59
  • Maybe worth mentioning `set +o xtrace` for Korn/POSIX-like shells as a more legible alternative to `set +x` (see also, `shopt -ou xtrace` in bash or `unsetopt xtrace`/`setopt noxtrace` / `options[xtrace]=off` in `zsh`, though I'd rather recommend the standard ones in those shells) – Stéphane Chazelas Jul 14 '22 at 12:19
  • See also the `(){set -o localoptions -o xtrace; cmd}` in `zsh` to set the option locally (here in an anonymous function) without using a subshell. – Stéphane Chazelas Jul 14 '22 at 12:22
55

You can stop debugging mode by set +x. See example page

Simply_Me
  • 1,742
  • 1
  • 12
  • 10
21

You have enabled debug mode, you need to turn it off.

Extract from the output of help set in the bash shell:

Using + rather than - causes these flags to be turned off.

So type set +x

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
2
$ set +x # is the opposite of set -x, and will reverse what you typed.

You can't find a man page just on set, because as you see below:

$ type set

set is a special shell builtin. While documented in the man page for your shell, presuming bash here, you can also get specific documentation with either

$ help set || builtin help set # luckily Bash has builtin help on builtin commands

The manual page on bash or sh is a good read, but it's a little long to sort out. The effective information you needed to un-set your -x is at the end before Exit Status: and reads:

Using + rather than - causes these flags to be turned off. The flags can also be used upon invocation of the shell. The current set of flags may be found in $-. The remaining n ARGs are positional parameters and are assigned, in order, to $1, $2, .. $n. If no ARGs are given, all shell variables are printed.

dlamblin
  • 373
  • 1
  • 3
  • 11
  • 1
    While not wrong, what have you added beyond the existing answers? – Jeff Schaller Mar 26 '18 at 12:50
  • @JeffSchaller It's edited for directness and brevity. When I needed this answer I had to read the whole page to find out the correct answer. In fact I gave up reading the accepted answer and just went to `help set` and read that. I tried to improve the accepted answer. https://unix.stackexchange.com/revisions/149137/4 It was accepted but then rejected. Like a news article, it starts with the most important information and assumes that at any point the reader may stop, with each next sentence and paragraph being less important than the proceeding. It's my SO style on unix se. – dlamblin Mar 27 '18 at 07:16