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


55

我正在使用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!

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

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

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


20
您似乎还以root用户身份登录。不要那样做!
Toby Speight

5
是的,我知道大多数时候都避免生根。这是在需要root用户的一次性测试环境中的VM上。
乍得'18

9
@TobySpeight这是刻板的,死记硬背的建议。
rackandboneman

2
@TobySpeight认真地讲,不要把它当作绝对的原则。告诉我,使用sudo -i运行一系列根级命令有什么问题?特别是当我调试某些东西时?
Duncan X Simpson

2
@TobySpeight如果您没有时间解释,请不要给出笼统的“建议”,这通常是无济于事的。
蒂姆(Tim)

Answers:


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.

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

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


11
是的 作为挖掘的一种更方便的替代方法man bash,您也可以help set
拉夫隆

5
传说中...我花在滚动手册bash页上的时间...谢谢!
阿提

1
开始我不拥有的bash之后,我的第一个命令始终是set -o vi。如果输入错误,set -ovi您将获得上述行为。
Guntram Blohm

至于为什么-我怀疑会有一个脚本源(即“ ../srciptname”而不是“ ./scriptname”),然后在取消设置-v之前退出,即最后应该“设置+ v”
jmullee18年

2
顺便说一句,我发现set -x除了控制流以外,它对于日志记录或调试其他功能更有用,因为它扩展了变量以显示实际正在运行的命令,例如,echo foo代替echo $my_string
Peter Cordes

11

至少在Bash 4.3上,此命令的作用类似于set -v

trap 'echo "$BASH_COMMAND"' DEBUG

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

trap -p DEBUG

要取消设置,请运行

trap - DEBUG
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.