虽然我有HISTFILESIZE
超过HISTSIZE
500 个,但进入“norc”shell 后,bash 历史记录会被破坏。我该如何在各种 shell 类型中保留历史记录数据?
这是一个实际的例子。
// on the normal shell (bash)
/mnt/c/pg$ wc ~/.bash_history
876 1997 19855 /home/user/.bash_history
/mnt/c/pg$ logout
PS > bash --noprofile --norc
// on the norc shell
bash-4.4$ wc ~/.bash_history
847 1947 19406 /home/user/.bash_history
// -> notice that .bash_history is trimmed to the default 500 lines. This is the problem.
bash-4.4$ exit
// again on the normal shell
PS > bash
/mnt/c/pg$ wc ~/.bash_history
848 1948 19439 /home/user/.bash_history
// -> once I enter to a norc shell, it affects the entire shell experiences
这是我的 .bashrc 和 .profile 的一部分
// .bashrc
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
// ..
// .profile
export HISTCONTROL=ignoredups:erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
export HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
// ..
答案1
使用空来运行它HISTFILE
,因此 shell 不会尝试更新默认文件:
HISTFILE= bash --noprofile --norc