Why is my Linux system repeating every command that I type?

55

6

I'm using a Ubuntu Linux system, and every command I enter is displayed on the next line, followed by the output of the command. For example:

root@dpkube165:~# ls
ls  <--- why is this here?
Desktop  Documents  Downloads 

root@dpkube165:~# date
date  <--- or this?
Mon Mar 19 11:24:59 EDT 2018

root@dpkube165:~# echo "Hello, world!"
echo "Hello, world!" <--- or this?
Hello, world!

I thought it might have to do with the prompt, which is as follows (PS1):

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

but reviewing online guides to prompt escape sequences didn't turn up anything obvious.

Chad

Posted 2018-03-19T15:31:30.963

Reputation: 1 343

20You also appear to be logged in as root. Don't do that! – Toby Speight – 2018-03-20T13:42:58.020

5Yes, I know to avoid root most of the time. This is on a VM in a throwaway testing environment where root is required. – Chad – 2018-03-20T19:16:34.317

9@TobySpeight this is hackneyed, rote advice. – rackandboneman – 2018-03-21T11:17:45.530

2@TobySpeight Seriously, don't push that as an absolute rule. Tell me, what's wrong with using sudo -i to run a series of root-level commands? Especially when I'm debugging something? – Duncan X Simpson – 2018-03-21T21:06:16.250

I didn't expect to have to explain something that obvious to users of [unix.se]! I thought everybody understood the general advice to use the root account for things that require the privilege, and ordinary user accounts for things that don't. If not, there's plenty of other resources to learn from, and I don't have the time for that kind of spoonfeeding right now. – Toby Speight – 2018-03-22T08:25:19.100

2@TobySpeight if you don’t have time to explain, don’t give blanket “advice” which is often unhelpful. – Tim – 2018-03-22T09:11:29.583

@Tim, the advice was given, understood and acknowledged - what's the problem? – Toby Speight – 2018-03-22T11:07:47.730

Answers

89

It looks like you have -v set (something is running set -v).

To reverse this, run set +v.

set [--abefhkmnptuvxBCEHPT] [-o option-name] [arg ...]
set [+abefhkmnptuvxBCEHPT] [+o option-name] [arg ...]
       Without  options, the name and value of each shell variable are displayed in a
       format that can be reused as input for setting or resetting the currently-set
       variables. Read-only variables cannot be reset. In posix mode, only shell
       variables are  listed. The output is sorted according to the current locale.
       When options are specified, they set or unset shell attributes. Any arguments
       remaining after option processing are treated as values for the positional
       parameters and are assigned, in order, to $1, $2, ...  $n.  Options, if
       specified, have the following meanings:

[...]

-v      Print shell input lines as they are read.

See the bash manpage (under the "Shell Builtin Commands" section) for more information on the set built-in command.

Alternatively run help set from within bash for more direct access to the help text.

Attie

Posted 2018-03-19T15:31:30.963

Reputation: 14 841

11Yep! As a slightly more convenient alternative to digging through man bash, you can also help set. – ravron – 2018-03-19T19:59:56.993

5You legend... The time I've spent scrolling in the bash manpage... thanks! – Attie – 2018-03-20T10:11:55.373

1My very first command after starting a bash that I don't own is always set -o vi. Mistype that as set -ovi and you'll get the above behaviour. – Guntram Blohm supports Monica – 2018-03-20T22:45:03.833

as to the Why - I would suspect there's a script being sourced (i.e. ". ./srciptname" instead of just "./scriptname") which then exits before it unsets -v, i.e. at end it should "set +v" – jmullee – 2018-03-21T00:16:21.817

2BTW, I find set -x more useful for logging, or debugging of things other than control-flow, because it expands variables to show what commands are actually being run, e.g. echo foo instead of echo $my_string – Peter Cordes – 2018-03-21T06:13:50.757

@GuntramBlohm You just described exactly what happened! – Chad – 2018-03-22T14:50:05.633

11

At least on Bash 4.3, this command has a similar effect to set -v:

trap 'echo "$BASH_COMMAND"' DEBUG

To check if this affects you, run

trap -p DEBUG

To unset it, run

trap - DEBUG

wjandrea

Posted 2018-03-19T15:31:30.963

Reputation: 497