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

我看到extglob已开启,但我想知道这是设置的位置。

$ shopt extglob extglob on $ 

没有在这些文件中找到它。

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

在我的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:~$ 

这是由~/.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 

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

 + . /usr/share/bash-completion/bash_completion ... ++ shopt -s extglob progcomp 

+ ‘表示源文件的级别,所以当我们从shopt命令查看一级时,我们看到/usr/share/bash-completion/bash_completion来源。

它在/usr/share/bash-completion/bash_completion文件下设置:

 shopt -s extglob progcomp 

~/.bashrc文件具有以下内容,如果未设置posix选项,则:

 if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion 

这意味着如果文件/usr/share/bash-completion/bash_completion存在,它将获取文件。

由于该文件包含设置extglob的行,因此将在声明交互式非登录shell时进行设置。