如何坚持bash历史?

Car*_*981 12 linux cygwin bash command-line bashrc

我不知道这是否符合预期,但我的历史记录不会跨会话保存。这就是说,如果我关闭窗口,那么当我再次打开它时,历史记录是空的。我怎样才能跨会话坚持它?

以下是您询问的命令的输出:

 set -o | grep history
history         on

$ grep -i history ~/.bashrc ~/.bash_profile ~/etc/bash.bashrc ~/etc/profile ~/.profile
/cygdrive/c/cygwin/home/car/.bashrc:# Make bash append rather than overwrite the history on disk
/cygdrive/c/cygwin/home/car/.bashrc:# History Options
/cygdrive/c/cygwin/home/car/.bashrc:# Don't put duplicate lines in the history.
/cygdrive/c/cygwin/home/car/.bashrc:# export PROMPT_COMMAND="history -a"
grep: /cygdrive/c/cygwin/home/car/etc/bash.bashrc: No such file or directory
grep: /cygdrive/c/cygwin/home/car/etc/profile: No such file or directory
/cygdrive/c/cygwin/home/car/.profile:if [ "x$HISTFILE" == "x/.bash_history" ]; then
/cygdrive/c/cygwin/home/car/.profile:  HISTFILE=$HOME/.bash_history

$ ls -la ~/ | grep history -> no output

$ echo $HISTFILE 
~/.bash_history
$ echo $HISTSIZE
500
$ echo $HISTFILESIZE 
500
Run Code Online (Sandbox Code Playgroud)

在下面的答案中描述的编辑之后,我现在得到:

grep -i hist .bashrc
# Make bash append rather than overwrite the history on disk
shopt -s histappend
# History Options
# Don't put duplicate lines in the history.
export HISTCONTROL="ignoredups"
# (added) A new shell gets the history lines from all previous shells
PROMPT_COMMAND='history -a'
# HISTIGNORE is a colon-delimited list of patterns which should be excluded.
Run Code Online (Sandbox Code Playgroud)

我仍然无法跨会话保存历史记录。我阅读了以下问题:

似乎没有人解决我的问题,包括下面那个人的答案,他们的问题从所谓的副本中得到了回答。

Car*_*981 10

好的,我发现出了什么问题。我无法关闭窗口,我必须键入“退出”才能正常关闭。


ter*_*don 8

好吧,看起来您~/.bashrc没有必要的选项。确保这些行在您的~/.bashrc

# Make Bash append rather than overwrite the history on disk:
shopt -s histappend
# A new shell gets the history lines from all previous shells
PROMPT_COMMAND='history -a'
# Don't put duplicate lines in the history.
export HISTCONTROL=ignoredups
Run Code Online (Sandbox Code Playgroud)