Skip to content

fix(dev): self-relaunch dev.sh under bash if invoked via sh/dash - #86

Merged
khoks merged 1 commit into
mainfrom
chore/dev-sh-bash-guard
May 16, 2026
Merged

khoks merged 1 commit into
mainfrom
chore/dev-sh-bash-guard

Conversation

@khoks

@khoks khoks commented May 16, 2026

Copy link
Copy Markdown
Owner

Summary

Reported by a user invoking the script with sh scripts/dev.sh:

dev.sh: line 48: syntax error: bad substitution
dev.sh: line 104: syntax error: unexpected "(" (expecting "fi")

The script's shebang (#!/usr/bin/env bash) only kicks in when you run ./dev.sh. An explicit sh dev.sh overrides it and hits dash/sh, which can't parse ${BASH_SOURCE[0]} (line 48) or COMPOSE_ARGS=(-f ...) (line 104).

Fix: prepend a POSIX-clean guard that re-execs under bash if $BASH_VERSION is unset, with a friendly error if bash isn't installed. Verified by running sh scripts/dev.sh --help and getting the proper help text.

Also bumped the --help sed range to match the new line numbers.

Test plan

  • sh scripts/dev.sh --help → re-execs and prints help (previously failed at line 48)
  • bash scripts/dev.sh --help still works unchanged
  • pnpm format:check clean

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.
@khoks
khoks merged commit 4658b56 into main May 16, 2026
1 check passed
@khoks
khoks deleted the chore/dev-sh-bash-guard branch May 16, 2026 02:32
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.

1 participant