对于某些选项,setopt 没有作用。
➜ ~ setopt | grep history
extendedhistory
➜ ~ setopt appendhistory
➜ ~ setopt | grep history # appendhistory apparently didn't get set
extendedhistory
➜ ~ setopt sharehistory
➜ ~ setopt | grep history # but sharehistory does
extendedhistory
sharehistory
为什么?
答案1
setopt
输出与当前仿真模式的偏差。在仿真appendhistory
中默认设置zsh
。
要显示所有选项的状态,您可以使用set -o
。
引用文档:
If no arguments are supplied, the names of all options currently set are printed. The form is chosen so as to minimize the differences from the default options for the current emulation (the default emulation being native zsh, shown as <Z> in *note Description of Options::). Options that are on by default for the emulation are shown with the prefix no only if they are off, while other options are shown without the prefix no and only if they are on. In addition to options changed from the default state by the user, any options activated automatically by the shell (for example, SHIN_STDIN or INTERACTIVE) will be shown in the list. The format is further modified by the option KSH_OPTION_PRINT, however the rationale for choosing options with or without the no prefix remains the same in this case.