default bashrc contains invalid ternary statement

Bug #1965728 reported by Kurt von Laven
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash (Ubuntu)
New
Undecided
Unassigned

Bug Description

Shellcheck detected an instance of https://github.com/koalaman/shellcheck/wiki/SC2015 in the .bashrc that ships with Ubuntu.

Here is the existing code:

test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"

It appears to be intended to behave like a ternary statement. The existing code evaluates `eval "$(dircolors -b)"` if `test -r ~/.dircolors` is true and `eval "$(dircolors -b ~/.dircolors)"` is false, which at face value doesn't appear to be the intention. According to Shellcheck, it should instead be:

if [ -r ~/.dircolors ]; then
    eval "$(dircolors -b ~/.dircolors)"
else
    eval "$(dircolors -b)"
fi

This ensures that the else case only executes when test -r ~/.dircolors is false.

ProblemType: Bug
DistroRelease: Ubuntu 21.10
Package: bash 5.1-3ubuntu2
ProcVersionSignature: Ubuntu 5.13.0-35.40-generic 5.13.19
Uname: Linux 5.13.0-35-generic x86_64
NonfreeKernelModules: nvidia_modeset nvidia
ApportVersion: 2.20.11-0ubuntu71
Architecture: amd64
CasperMD5CheckResult: unknown
CurrentDesktop: ubuntu:GNOME
Date: Mon Mar 21 00:28:18 2022
InstallationDate: Installed on 2020-12-09 (467 days ago)
InstallationMedia: Ubuntu 20.10 "Groovy Gorilla" - Release amd64 (20201022)
ProcEnviron:
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: bash
UpgradeStatus: Upgraded to impish on 2021-10-18 (154 days ago)

Revision history for this message
Kurt von Laven (lighthunter) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.