From fdc006f3d84758bdc7ba4c93d8cb3c938a81b557 Mon Sep 17 00:00:00 2001 From: Rahul Singh Khokhar Date: Fri, 15 May 2026 19:27:32 -0700 Subject: [PATCH] fix(dev): self-relaunch dev.sh under bash if invoked via sh/dash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a user types `sh scripts/dev.sh` (or runs it under dash, or under any non-bash POSIX shell), they'd hit: dev.sh: line 48: syntax error: bad substitution dev.sh: line 104: syntax error: unexpected "(" (expecting "fi") …because dev.sh uses bash-only features (${BASH_SOURCE[0]}, array assignment, wait -n). The shebang only takes effect for `./dev.sh` invocations; an explicit `sh dev.sh` ignores it. Fix: add a POSIX-compatible guard at the top that re-execs under bash if ${BASH_VERSION} isn't set, with a friendly error if bash isn't installed at all. The guard itself uses only POSIX-clean syntax so sh can parse it. Also bump the --help sed range to match the new line numbers. --- scripts/dev.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/dev.sh b/scripts/dev.sh index eacbb26..425e02d 100644 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -1,4 +1,17 @@ #!/usr/bin/env bash +# Self-relaunch under bash if we were invoked via `sh dev.sh`, or under dash, or any other +# non-bash POSIX shell. The script uses bash-only features (arrays, ${BASH_SOURCE[0]}, +# `wait -n`, etc.); under sh you'd hit `bad substitution` at line 48 or `unexpected "("` +# at the first array assignment. The check itself is POSIX-clean so sh can parse it. +if [ -z "${BASH_VERSION:-}" ]; then + if command -v bash >/dev/null 2>&1; then + exec bash "$0" "$@" + else + echo "ERROR: bash is required to run this script. Install bash (or Git for Windows) and retry." >&2 + exit 1 + fi +fi + # scripts/dev.sh — one-shot dev environment bootstrapper for LearnPro. # # What it does: @@ -58,7 +71,9 @@ for arg in "$@"; do --fresh) FRESH=1 ;; --down) DOWN_ONLY=1 ;; -h|--help) - sed -n '2,48p' "$0" | sed 's/^# \{0,1\}//' + # Print the script's leading description comment block (the "scripts/dev.sh — …" + # banner through the No-API-key note). Skip the self-relaunch guard at the top. + sed -n '15,54p' "$0" | sed 's/^# \{0,1\}//' exit 0 ;; *) echo "Unknown flag: $arg" >&2; exit 2 ;;