为什么我的 Linux 系统会重复我输入的每个命令?

Cha*_*had 55 linux command-line

我使用的是 Ubuntu Linux 系统,我输入的每个命令都显示在下一行,然后是命令的输出。例如:

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!
Run Code Online (Sandbox Code Playgroud)

我认为可能与提示有关,如下(PS1):

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$
Run Code Online (Sandbox Code Playgroud)

但是查看在线指南以提示转义序列并没有发现任何明显的问题。

Att*_*tie 89

看起来您已经-v设置(正在运行set -v)。

要扭转这种情况,请运行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.
Run Code Online (Sandbox Code Playgroud)

有关内置命令的更多信息,请参阅bash联机帮助页(在“ Shell 内置命令”部分下)set

或者help set从内部运行bash以更直接地访问帮助文本。

  • 是的!作为通过“man bash”进行挖掘的更方便的替代方法,您还可以使用“help set”。 (11认同)
  • 你这个传奇......我在`bash`联机帮助页中花费的时间......谢谢! (5认同)
  • 顺便说一句,我发现 `set -x` 对记录或调试控制流以外的东西更有用,因为它扩展变量以显示*实际*正在运行的命令,例如 `echo foo` 而不是 `echo $my_string ` (2认同)

wja*_*rea 11

至少在 Bash 4.3 上,此命令与以下效果类似set -v

trap 'echo "$BASH_COMMAND"' DEBUG
Run Code Online (Sandbox Code Playgroud)

要检查这是否会影响您,请运行

trap -p DEBUG
Run Code Online (Sandbox Code Playgroud)

要取消设置,请运行

trap - DEBUG
Run Code Online (Sandbox Code Playgroud)