Skip to content

fix(brief): avoid bash 3.2 parse error from apostrophe in heredoc#132

Open
RevazBakuradze wants to merge 1 commit into
kunchenguid:mainfrom
RevazBakuradze:fix-bash32-heredoc
Open

fix(brief): avoid bash 3.2 parse error from apostrophe in heredoc#132
RevazBakuradze wants to merge 1 commit into
kunchenguid:mainfrom
RevazBakuradze:fix-bash32-heredoc

Conversation

@RevazBakuradze

Copy link
Copy Markdown

Problem

bin/fm-brief.sh fails to parse under the bash that ships with macOS (GNU bash 3.2.57, still the default /bin/bash). The script's shebang is #!/usr/bin/env bash, so on a stock macOS machine it runs under 3.2 and dies before doing anything:

$ bash -n bin/fm-brief.sh
bin/fm-brief.sh: line 211: unexpected EOF while looking for matching `''
bin/fm-brief.sh: line 263: syntax error: unexpected end of file

The cause is a bash 3.2 parser bug: a lone single quote (apostrophe) inside a here-doc that is nested in a command substitution (VAR=$(cat <<EOF ... EOF)) is mis-parsed as the start of a single-quoted string that never closes. Line 211, inside the no-mistakes DOD=$(cat <<EOF ...) block, contains no-mistakes', which trips it. Bash 4+ parses the same construct correctly, so this only affects users on the stock macOS bash.

Minimal repro:

cat > /tmp/repro.sh <<'OUTER'
X=$(cat <<EOF
no-mistakes' own guidance
EOF
)
OUTER
bash -n /tmp/repro.sh   # 3.2: "unexpected EOF while looking for matching `''"; 4+: clean

Fix

Rephrase that one line to remove the lone apostrophe (no escaping, keeps it readable):

Follow no-mistakes' own guidance for the mechanics: -> Follow the no-mistakes guidance for the mechanics:

One line changed; no behavior change. It is the only lone apostrophe inside any of the script's $(cat <<EOF ...) blocks.

Verification

  • Before: bash -n bin/fm-brief.sh -> 2 errors (under bash 3.2.57).
  • After: bash -n bin/fm-brief.sh -> clean (exit 0), and scaffolding still produces valid briefs.

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