FS#66449 - [bash] /etc/bash.bashrc may result in initial failing return status ( $? )

Attached to Project: Arch Linux
Opened by Eli Schwartz (eschwartz) - Tuesday, 28 April 2020, 14:44 GMT
Last edited by Tobias Powalowski (tpowa) - Sunday, 05 February 2023, 09:03 GMT
Task Type General Gripe
Category Packages: Core
Status Closed
Assigned To Tobias Powalowski (tpowa)
Felix Yan (felixonmars)
Levente Polyak (anthraxx)
Giancarlo Razzolini (grazzolini)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

The final line of https://git.archlinux.org/svntogit/packages.git/tree/trunk/system.bashrc?h=packages/bash checks to see if bash-completion is installed, and if so, sources it. In the event that bash-completion is *not* installed, this causes the final command in /etc/bash.bashrc to be [ -r /usr/share/bash-completion/bash_completion ], which fails. This is a well-documented caveat to using && for conditionals.

If the user does not have a bashrc, then upon initially opening a new interactive shell, echo $? returns "1". This can be user visible in some cases like when setting PS1 to something which displays the previous command's return status, but in .profile instead of .bashrc, then opening a new interactive shell. The PS1 then has a rather confusing value in it.

(initially reported by a confused user in #bash on freenode)

A better default bashrc would ensure it finishes off with a successful command -- this can be done by switching:

[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion

to

if [ -r /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
fi

This is a good time to perform this minor cosmetic change, since bash is already flagged out of date for patch 5.0.016 -> 5.0.017
This task depends upon

Closed by  Tobias Powalowski (tpowa)
Sunday, 05 February 2023, 09:03 GMT
Reason for closing:  Fixed
Additional comments about closing:  5.1.016-2
Comment by Tobias Powalowski (tpowa) - Tuesday, 31 January 2023, 18:59 GMT
fixed in bash trunk.
Comment by Tobias Powalowski (tpowa) - Tuesday, 31 January 2023, 20:53 GMT
bash-5.1.016-2

Loading...