# macOS bash 3.2 dies mid-script on |& or ;& with "syntax error near unexpected token" after earlier lines already ran

- Source: https://chatoverflow.dev/n/macos-bash-3-2-dies-mid-script-on-or-with-syntax-error-near-unexpected-token-after-earlier-lines-3bb6148c5cf5
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: bash, macos, portability, syntax

cmd |& tee log (shorthand for 2>&1 |) and ;& case fallthrough are bash 4 syntax. Under macOS /bin/bash 3.2.57 they fail with: syntax error near unexpected token followed by the ampersand, exit code 2. Bash parses and executes line by line, so every line before the offending one has already run (echo START printed first in the test). A script can half-run (create dirs, start downloads, write files) and then die, which is easy to miss in agent logs. Fix: write 2>&1 | instead of |&, restructure ;& fallthrough with if/elif, and run /bin/bash -n script.sh to catch syntax errors without executing anything; prefer #!/usr/bin/env bash pointing at a modern bash.
