Skip to content

(short issue descriptionDuplicate ~/.local/bin in PATH due to incorrect path existence check in Amazon Q shell scripts) #9531

Closed
@evgenijkostin

Description

@evgenijkostin

Describe the bug

Amazon Q shell scripts (profile.pre.bash and profile.post.bash) incorrectly check for the existence of ~/.local/bin in the PATH
variable, which leads to this path being added twice to the PATH. The current check [[ ":$PATH:" != ":$_Q_LOCAL_BIN:" ]] doesn't
properly detect if the path is already present.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The PATH variable should contain ~/.local/bin only once. The check in Amazon Q shell scripts should correctly detect if the path is
already present in PATH and not add it again.

Current Behavior

The PATH variable contains ~/.local/bin twice:
/home/user/.local/bin:/other/paths:/home/user/.local/bin

This happens because:

  1. ~/.profile adds ~/.local/bin to PATH
  2. Amazon Q shell scripts (profile.pre.bash and profile.post.bash) add it again due to incorrect path existence check

Reproduction Steps

  1. Have ~/.local/bin added to PATH in ~/.profile (standard in many Linux distributions)
  2. Install Amazon Q CLI
  3. Check PATH variable with echo $PATH
  4. Observe that ~/.local/bin appears twice in the PATH

Possible Solution

Replace the current check in both profile.pre.bash and profile.post.bash:

From:
bash
[[ ":$PATH:" != ":$_Q_LOCAL_BIN:" ]] && PATH="${PATH:+"$PATH:"}$_Q_LOCAL_BIN"

To a more accurate check using regex:
bash
if [[ ! "$PATH" =~ (^|:)"$_Q_LOCAL_BIN"(:|$) ]]; then
PATH="${PATH:+"$PATH:"}$_Q_LOCAL_BIN"
fi

This regex properly checks if the path exists as a complete segment in the PATH variable.

Additional Information/Context

This issue doesn't cause functional problems but is a minor inefficiency as the shell has to search the same directory twice when
looking for executables.

CLI version used

Amazon Q CLI (latest version)

Environment details (OS name and version, etc.)

Linux (Ubuntu/Debian-based distribution)

Metadata

Metadata

Labels

bugThis issue is a bug.p3This is a minor priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions