fix(scripts): local_test.sh 被 sh(POSIX 模式 bash) 调起报进程替换语法错误——首行加守卫重执行到普通 bash

macOS /bin/sh = bash --posix:设 BASH_VERSION 但禁用进程替换,line 56 的 2> >(grep ...)
在解析时即报 syntax error near unexpected token '>'。守卫检测 SHELLOPTS 含 posix 或非 bash
时 exec bash 重执行,honor 脚本文档里的 'sh scripts/local_test.sh' 用法。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-11 08:20:22 +08:00
parent 51c0cfda56
commit 8216ee321f
+12
View File
@@ -10,6 +10,18 @@
# 版本号 = 最新 client-v* tag 的 patch+1 加 -dev 后缀(如 v1.1.4-dev),
# App 内显示走 APP_VERSION dart-defineupdate_provider.currentAppVersion),
# 与 CI 同一读取链路——本地构建不再显示 pubspec 旧版本(2026-07-04 修复)。
#
# 本脚本用到 bash 专属特性(数组、进程替换 `>(...)`)。若被 `sh` 调起(macOS 的
# /bin/sh 实为 bash --posix:会设 BASH_VERSION 但禁用进程替换,导致下方 xcodebuild
# 那行报 `syntax error near unexpected token '>'`),或被 dash 等非 bash 调起,则在
# 解析到那行之前先重执行到普通模式 bash。此判断须是第一条可执行语句。
_posix=no
case ":${SHELLOPTS:-}:" in *:posix:*) _posix=yes ;; esac
if [ -z "${BASH_VERSION:-}" ] || [ "$_posix" = yes ]; then
exec bash "$0" "$@"
fi
unset _posix
set -euo pipefail
export PATH="/opt/homebrew/bin:$PATH"