Skip to content

binary-installer/install.sh appends duplicate PATH entries due to grep -q command substitution #13394

@gkapetanakis

Description

@gkapetanakis

Issue description

binary-installer/install.sh has non-idempotent PATH insertion logic in bash profile handling.

Problematic checks:

  • if [[ ! $(grep -q '.serverless/bin' $SHELL_CONFIG) ]]; then (around lines 74, 80)

grep -q intentionally produces no stdout, so $(grep -q ...) expands to an empty string regardless of match result.
As a result, [[ ! $(...) ]] evaluates true and add_to_path runs even when .serverless/bin is already present.

Effect

Running the installer repeatedly appends duplicate blocks like:

# Added by serverless binary installer
export PATH="$HOME/.serverless/bin:$PATH"

This causes shell startup files to grow and can repeatedly prepend the same directory in PATH.

Reproduction

Ensure ~/.bash_profile exists and already contains .serverless/bin.
Run binary-installer/install.sh.
Observe that the installer appends another # Added by serverless binary installer block.
Run it again and see additional duplicates.

Expected behavior

Installer should be idempotent and only add PATH config when .serverless/bin is not already configured.

Suggested fix

Use grep exit status directly instead of command substitution, for example:

if [[ ! -r "$SHELL_CONFIG" ]] || ! grep -q '.serverless/bin' "$SHELL_CONFIG"; then
  add_to_path "$SHELL_CONFIG"
fi

Relevant file: binary-installer/install.sh.

Context

N/A

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions