Package: bash
Version: 5.2.37-1
Severity: important

Dear Maintainer,

one of the ways bash (in debian, because the configuration file is
crafted by debian not upstream) currently checks if it is run
interactively is in the file /etc/bash.bashrc where it performs:

```
# If not running interactively, don't do anything
[ -z "${PS1-}" ] && return
```

This is checking whether PS1 is empty or not. An interactive bash shell
*typically* has a non-empty PS1, but it is not a guarantee that bash is
run interactively. It cannot be relied on, and it has indeed led to
breakage problem on my end.

A trivial way of demonstrating the problem:

```
PS1= bash -ic 'declare -p PS1'
```
which shows that bash is running interactively (has the 'i' flag), but
PS1 is empty.

The correct way to check if bash is run interactively is to verify the
presence of the 'i' flag in the bash options.

I provide three different examples of how this could be done in the
/etc/bash.bashrc file:

```
case $- in
  *i*) ;;
    *) return ;;
esac
```

or

```
[[ $- != *i* ]] && return
```

or

```
[[ $- == *i* ]] || return
```

Pick whichever one you like, I prefer the last one because it is short,
to the point, and is checking for presence of a flag rather than absence
of a flag.

Please try to have this fixed in time for debian trixie, it is a trivial
change that makes the behavior of bash more reliable and avoids
problems.

Thank you.


-- System Information:
Debian Release: trixie/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.12.11-amd64 (SMP w/2 CPU threads; PREEMPT)
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages bash depends on:
ii  base-files   13.6
ii  debianutils  5.21
ii  libc6        2.40-6
ii  libtinfo6    6.5+20250125-2

Versions of packages bash recommends:
ii  bash-completion  1:2.16.0-7

Versions of packages bash suggests:
pn  bash-doc  <none>

-- no debconf information

Reply via email to