I'd like to propose a slightly modified patch:

diff -urN bash-5.1.orig/debian/etc.bash.bashrc bash-5.1/debian/etc.bash.bashrc
--- bash-5.1.orig/debian/etc.bash.bashrc        2022-03-27 18:36:06.000000000 
+0000
+++ bash-5.1/debian/etc.bash.bashrc     2022-03-27 18:36:06.000000000 +0000
@@ -4,7 +4,7 @@
 # this file has to be sourced in /etc/profile.

 # If not running interactively, don't do anything
-[ -z "$PS1" ] && return
+[[ $- = *i* ]] || return

 # check the window size after each command and, if necessary,
 # update the values of LINES and COLUMNS.
@@ -17,7 +17,7 @@

 # set a fancy prompt (non-color, overwrite the one in /etc/profile)
 # but only if not SUDOing and have SUDO_PS1 set; then assume smart user.
-if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
+if ! [ -n "${SUDO_USER:-}" -a -n "${SUDO_PS1:-}" ]; then
   PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
 fi


which avoids the assumption that an interactive shell always has PS1 set
(unlikely to be false but not impossible)

Reply via email to