Bash 历史命令执行与!刷新历史记录后砰的一声无法正常工作

Bash 历史命令执行与!刷新历史记录后砰的一声无法正常工作,bash,Bash,我对bash历史有问题 假设我用history | grep forever调用历史。 然后,包含forever的所有以前的命令都会显示相应的编号 如果我现在使用相应的编号(例如,!2121)执行其中一个命令,则会调用与历史记录不同的命令,而不是与该编号关联的命令。我做错了什么 如果我调用历史而不使用greping,则执行效果将如预期的那样 Thx 可怕的例子: ... 1742 forever stop 0 1743 forever -o out.log -e err.log sta

我对bash历史有问题

假设我用
history | grep forever
调用历史。 然后,包含forever的所有以前的命令都会显示相应的编号

如果我现在使用相应的编号(例如,
!2121
)执行其中一个命令,则会调用与历史记录不同的命令,而不是与该编号关联的命令。我做错了什么

如果我调用历史而不使用greping,则执行效果将如预期的那样

Thx

可怕的例子:

 ...
 1742  forever stop 0
 1743  forever -o out.log -e err.log start -c nodemon hotnews.js
 1784  forever list
 1814  forever list
 2496  forever -o out.log -e err.log start -c nodemon hotnews.js
 2498  forever -o out.log -e err.log start -c nodemon hotnews.js
 2957  forever -o out.log -e err.log start -c nodemon hotnews.js
 3292  forever -o out.log -e err.log start -c nodemon hotnews.js
 3452  forever -o out.log -e err.log start -c nodemon hotnews.js
 3603  forever -o out.log -e err.log start -c nodemon hotnews.js
 3614  history | grep forever
 [~]$ !1784
 npm uninstall express-flash
 npm WARN uninstall not installed in /home/development/node_modules: "express-flash"
 [~]$
编辑:

我记得我在.bashrc中更改了历史记录属性:

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
export HISTCONTROL=ignoreboth:erasedups

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
export HISTSIZE=100000
export HISTFILESIZE=100000

# ignoriert einfache Befehle wie cd
export HISTIGNORE='cd:ls:bg:fg:history'

export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

这些条目可能有什么错误吗?

你可能有一些空行或其他愚蠢的东西。bash_历史。 尝试以下方法查找错误:

history | tr -d '[:blank:]' > foo
cat -n .bash_history | tr -d '[:blank:] > bar
diff foo bar

您确定该数字与
.bash\u history
文件中的命令对应吗?是的,请看上面的示例。好的,对不起。你说得对,迈克尔。history命令的输出与.bash_历史(cat-n.bash_历史)的数字不同。这是怎么回事?history命令的输出与.bash_历史(cat-n.bash_历史)的数字不同。这怎么可能?我认为.bash_历史文件是history命令的基础。它应该是相同的,但在hist中读取时忽略空行(可能还有其他内容)。因此,看看那里的数字开始不同。