URL: <https://savannah.gnu.org/bugs/?68734>
Summary: shopt -u expand_aliases has no effect when executed
in a trap/PROMPT_COMMAND/bind/etc.
Group: The GNU Bourne-Again SHell
Submitter: cubernetes
Submitted: Fri 02 Oct 2026 01:16:30 PM UTC
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Unlocked
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Fri 02 Oct 2026 01:16:30 PM UTC By: cubernetes <cubernetes>
Reproducer:
```bash
env -i bash --noprofile --rcfile <(echo 'alias foo="echo EXPANDED"; trap
"shopt -u expand_aliases; trap - DEBUG" DEBUG') -ic $'echo $BASH_VERSION;shopt
expand_aliases\nfoo\nshopt -u expand_aliases\nfoo'
```
Stdout + Stderr:
```
5.3.9(1)-release
expand_aliases off
EXPANDED
foo: command not found
```
The interactive shell turns on alias expansion by default. But before the
first command of the first line runs, the DEBUG trap is executed which should
turn off alias expansion.
When the `shopt expand_aliases` is then executed, it does indeed show that
alias expansion is off.
However, when `foo` is run on a separate line, it does actually expand to its
alias, which contradicts with the result of `shopt expand_aliases`.
The setting is only truly turned off by a `shopt -u expand_aliases`.
The same bug occurs with PROMPT_COMMAND, bind -x, and possibly other places as
well.
One place where I though the bug might happen but actually doesn't, is
fork-free command substitution in prompt strings:
```console
bash-5.3$ PS1='${ shopt -u expand_aliases;}'$PS1
bash-5.3$ PS0='${ shopt -u expand_aliases;}'
bash-5.3$ :
bash-5.3$ shopt expand_aliases
expand_aliases off
bash-5.3$ alias foo=bar
bash-5.3$ foo
bash: foo: command not found
bash-5.3$
```
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?68734>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
