Ubuntu – Where is bash’s “shopt extglob” turned on for the interactive shell

bashbashrc

I see that extglob is on but I'd like to know where this is set.

$ shopt extglob
extglob         on
$

Didn't find it in these files.

  • ~/.bashrc
  • ~/.bash_profile
  • ~/.profile
  • /etc/bashrc (no such file)
  • /etc/bash.bashrc

Best Answer

On my 14.04 VM, I found it in /usr/share/bash-completion/bash_completion:

ubuntu@ubuntu:~$ grep extglob /usr/share/bash-completion/bash_completion 
shopt -s extglob progcomp
ubuntu@ubuntu:~$ 

This is sourced by ~/.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

This can be figured out by running bash -x, which shows all sourced startup files and their commands. Run script -c "bash -x", then exit in the new interactive shell, then examine the typescript file output from script:

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

...

++ shopt -s extglob progcomp

The +'s indicate the level of sourced file, so when we look one level up from the shopt command, we see /usr/share/bash-completion/bash_completion is sourced.