Skip to content

fix: make all 18 bin/ scripts CDPATH-safe#837

Open
Ziadstr wants to merge 1 commit intogarrytan:mainfrom
Ziadstr:fix/cdpath-safe-all-bin
Open

fix: make all 18 bin/ scripts CDPATH-safe#837
Ziadstr wants to merge 1 commit intogarrytan:mainfrom
Ziadstr:fix/cdpath-safe-all-bin

Conversation

@Ziadstr
Copy link
Copy Markdown

@Ziadstr Ziadstr commented Apr 5, 2026

Summary

Root cause

When CDPATH is set (common with zsh users, zoxide, or custom navigation), cd prints the resolved path to stdout. This doubles the output of $(cd ... && pwd), corrupting GSTACK_DIR, SCRIPT_DIR, and REPO_ROOT assignments. Most visibly, gstack-update-check silently exits because VERSION_FILE becomes a two-line string.

Fix

# Before (broken with CDPATH):
GSTACK_DIR="$(cd "$(dirname "$0")/.." && pwd)"

# After (works with any CDPATH):
GSTACK_DIR="$(cd "$(dirname "$0")/.." >/dev/null && pwd)"

All 18 scripts fixed

dev-setup, dev-teardown, gstack-community-dashboard, gstack-extension, gstack-learnings-log, gstack-learnings-search, gstack-platform-detect, gstack-relink, gstack-repo-mode, gstack-review-log, gstack-review-read, gstack-specialist-stats, gstack-telemetry-log, gstack-telemetry-sync, gstack-timeline-log, gstack-timeline-read, gstack-uninstall, gstack-update-check.

Testing

bash -n bin/dev-setup bin/dev-teardown bin/gstack-community-dashboard \
  bin/gstack-extension bin/gstack-learnings-log bin/gstack-learnings-search \
  bin/gstack-platform-detect bin/gstack-relink bin/gstack-repo-mode \
  bin/gstack-review-log bin/gstack-review-read bin/gstack-specialist-stats \
  bin/gstack-telemetry-log bin/gstack-telemetry-sync bin/gstack-timeline-log \
  bin/gstack-timeline-read bin/gstack-uninstall bin/gstack-update-check

All 18 pass syntax check. Fix verified with CDPATH='.:/tmp' set.

Note: PR #836 fixes 7 of 18 scripts. This PR covers all 18.

Fixes #824

…uption

When CDPATH is set, cd prints the resolved path to stdout, corrupting
$(cd ... && pwd) assignments. This breaks all bin/ scripts by doubling
the directory path in variable assignments.

Fix: redirect cd stdout to /dev/null in all path resolution patterns.
pwd still outputs the correct path to stdout for the command substitution.

Fixes garrytan#824
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CDPATH breaks all bin/ scripts — cd outputs path to stdout, corrupting variable assignments

1 participant