bash 的“shopt extglob”在哪里为我的交互式 shell 打开?

Joh*_*udd 7 bash bashrc

我看到 extglob 已打开,但我想知道它的设置位置。

$ shopt extglob
extglob         on
$
Run Code Online (Sandbox Code Playgroud)

在这些文件中没有找到。

  • ~/.bashrc
  • ~/.bash_profile
  • ~/.profile
  • /etc/bashrc (没有这样的文件)
  • /etc/bash.bashrc

Dig*_*uma 9

在我的 14.04 VM 上,我在/usr/share/bash-completion/bash_completion以下位置找到了它:

ubuntu@ubuntu:~$ grep extglob /usr/share/bash-completion/bash_completion 
shopt -s extglob progcomp
ubuntu@ubuntu:~$ 
Run Code Online (Sandbox Code Playgroud)

这是来自~/.bashrc

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
Run Code Online (Sandbox Code Playgroud)

这可以通过运行来解决bash -x,它显示了所有来源的启动文件及其命令。运行script -c "bash -x",然后exit在新的交互式 shell 中,然后检查typescript脚本的文件输出:

+ . /usr/share/bash-completion/bash_completion

...

++ shopt -s extglob progcomp
Run Code Online (Sandbox Code Playgroud)

+的指示源文件的级别,所以当我们从寻找一个级别shopt的命令,我们可以看到/usr/share/bash-completion/bash_completion其来源。