7

To avoid the XY problem scenario, I'll explain why I'm asking this question.

I remember I had shopt -s extglob set in my ~/.bashrc file, because things like @(pattern-list) do work.

However, I've just looked into ~/.bashrc and that option is not set.

So I decided to see where it comes from, and discovered that

  • if I launch another shell via bash --norc and then run shopt I see the line extglob off,
  • whereas, if I launch it via bash --rcfile /dev/null, then shopt shows that extglob on,

which doesn't really help me in find out which file is extglob is set in.

Based on a comment, PS4=' $BASH_SOURCE:$LINENO: ' bash -lixc true |& grep extglob gives

   /usr/share/bash-completion/bash_completion:45: shopt -s extglob progcomp
   /usr/share/bash-completion/bash_completion:45: shopt -s extglob progcomp
6
  • 3
    A quick check using strace -e openat shows bash --rcfile /dev/null opens /etc/bash.bashrc in my Ubuntu 18.04, but bash --norc doesn't.
    – muru
    Mar 11, 2021 at 8:24
  • Please post the output of grep -H extglob ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login ~/.bash_aliases /etc/bash.bashrc /etc/profile /etc/profile.d/* /etc/environment 2> /dev/null
    – terdon
    Mar 11, 2021 at 11:02
  • @terdon, no output, exist status 2.
    – Enlico
    Mar 11, 2021 at 13:07
  • 3
    Also try PS4=' $BASH_SOURCE:$LINENO: ' bash -lixc true |& grep extglob
    – muru
    Mar 11, 2021 at 15:40
  • 2
    As you've discovered, on Arch (and other distros) Bash sources /etc/bash.bashrc (based on a compile-time setting). Even when --rcfile is specified. This doesn't contradict man bash ("--rcfile file Execute commands from file instead of the standard personal initialization file ~/.bashrc if the shell is interactive") (it is different on Debian, see the relevant bug report). This unintuitive behavior has been reported upstream as a bug, but the maintainer seems to diagree.
    – fra-san
    Mar 11, 2021 at 16:47

1 Answer 1

9

On Debian/Ubuntu, there's also /etc/bash.bashrc, which Bash reads similarly to ~/.bashrc. Using it is a compile time option, and I understand Red Hat does a similar thing by just sourcing a similar file in /etc/ from the per-user .bashrc.

The Debian documentation does seem to imply --rcfile should override both, as well as --norc inhibits reading both:

--norc Do not read and execute the system wide initialization file /etc/bash.bashrc and the personal initialization file ~/.bashrc if the shell is interactive.

--rcfile file Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc

But like @muru said in a comment, that seems wrong, --rcfile /dev/null still reads /etc/bash.bashrc. So, look there for the shopt.

3
  • The only shopt is /etc/bash.bashrc for me is [[ $DISPLAY ]] && shopt -s checkwinsize. By the way, I've update the question specifying I'm on ArchLinux.
    – Enlico
    Mar 11, 2021 at 10:56
  • @Enlico, yep. Hard to say what Archlinux does, but their wiki says that "All interactive shells source /etc/bash.bashrc and ~/.bashrc", which does sound similar to the Debian behaviour (that is, the file name is the same). You could check to see if any of those bashrc files sources other scripts (. filename or source filename). Or indeed just grep -re shopt /etc/ :D
    – ilkkachu
    Mar 11, 2021 at 12:06
  • Yes, Bash is compiled setting -DSYS_BASHRC to /etc/bash.bashrc on Arch. And /etc/bash.bashrc sources /usr/share/bash-completion/bash_completion if that file exists.
    – fra-san
    Mar 11, 2021 at 16:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .