我们对histcmd了解多少?
HISTCMD
The history number, or index in the history list, of the current
command. Assignments to HISTCMD are ignored. If HISTCMD is unset,
it loses its special properties, even if it is subsequently reset.
我们还能从手册中学到哪些秘密呢?
HISTCONTROL
A colon-separated list of values controlling how commands are saved
on the history list. If the list of values includes ignorespace,
lines which begin with a space character are not saved in the his‐
tory list. A value of ignoredups causes lines matching the previous
history entry to not be saved. A value of ignoreboth is shorthand
for ignorespace and ignoredups. A value of erasedups causes all
previous lines matching the current line to be removed from the his‐
tory list before that line is saved. Any value not in the above
list is ignored. If HISTCONTROL is unset, or does not include a
valid value, all lines read by the shell parser are saved on the
history list, subject to the value of HISTIGNORE. The second and
subsequent lines of a multi-line compound command are not tested,
and are added to the history regardless of the value of HISTCONTROL.
具体来说:
ignoredups 的值会导致与上一个历史记录条目匹配的行不被保存。
这是问题的原因吗?也许是...
$ echo $HISTCONTROL
ignoredups:
...但可能性不大。
我们能在最近的bash中复现这个问题吗?
$ source init_things
7615
$ . init_things
7616
不,其实不行。我们能在bash 4.3中重现吗?
$ . init_things
1
是的!
CHANGELOG中有几行关于HISTCMD的说明,但都没有描述这个特定问题。我猜这只是在使用source
时初始化HISTCMD时遇到的一个错误。
set -o history
。 - Dominique Baldo