Skip to content

with-managed-process.sh fails on bash 3.2 (macOS system bash) due to negative array index #1

Description

@azuresurf

Summary

scripts/with-managed-process.sh uses negative array subscripts (${START_ARGS[-1]}), which require bash 4.3+. On macOS, the system bash is permanently stuck at 3.2.57 (Apple ships GPLv2 bash only), so the wrapper fails out of the box for macOS users who don't have a Homebrew bash on PATH.

Environment

  • macOS (Apple Silicon), /bin/bash = GNU bash 3.2.57(1)-release
  • commit: 98bd7f3

Repro

./scripts/with-managed-process.sh --name web \
  --command 'python3 -m http.server 18924 --bind 127.0.0.1' \
  --port 18924 --timeout 30 -- 'curl -fsS http://127.0.0.1:18924'

Result:

with-managed-process.sh: line 31: START_ARGS: bad array subscript

Root cause

Lines 31–32 reference the just-pushed element via ${START_ARGS[-1]}. Negative indexing is unsupported before bash 4.3.

Suggested fix (bash 3.2 compatible)

Capture the pushed value before shift instead of indexing from the end:

  START_ARGS+=("$1")
  LAST_ARG="$1"
  shift
  if [ "$#" -gt 0 ] && [ "$LAST_ARG" != "--help" ]; then
    case "$LAST_ARG" in

This is semantically identical and works on bash 3.2+.

Secondary note

The scripts/*.sh files ship without the execute bit (mode 0644), so invoking them by path gives permission denied until chmod +x is run. Consider committing them as executable.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions