From 63b87e20d40c4327dedc930221d903af7a5f629a Mon Sep 17 00:00:00 2001 From: codes-factory-of-bg Date: Tue, 21 Jul 2026 20:56:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(install):=20place=5Fconfig=5Ftemplate=20bac?= =?UTF-8?q?kup=20=E5=8F=98=E9=87=8F=20bash=203.2=20=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS 自带 bash 3.2 在 set -eu 下对 `local var=$(cmd)` 有已知坑, 升级模式跑到 'Checking config health' 时报 `backup?: unbound variable` (line 1169 cp $backup). 修法: - backup 在函数顶部预绑定为空串 (local need_place=0 reason="" backup=""), 永不 unbound - 后缀改用 $$.${RANDOM:-0} (始终有值、无命令替换), 弃用 $(date +%s ...) - 消除 local-带-命令替换 模式, bash 3.2/5 通用 --- scripts/install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 38a1af13..82691f68 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1146,7 +1146,7 @@ place_config_template() { ui_error "config template 缺失:$tmpl(tarball 损坏?)" return 1 fi - local need_place=0 reason="" + local need_place=0 reason="" backup="" if [[ ! -f "$config_path" ]]; then need_place=1; reason="不存在" elif [[ "$FORCE_RUNTIME" == "true" ]]; then @@ -1165,7 +1165,9 @@ place_config_template() { fi if [[ "$need_place" == "1" ]]; then if [[ -f "$config_path" ]]; then - local backup="${config_path}.bak.$(date +%s 2>/dev/null || echo 0)" + # bash 3.2(macOS 自带)在 set -eu 下对 `local var=$(cmd)` 有已知坑, + # 故 backup 已在上面预绑定为空串,这里用 $$.$RANDOM(始终有值、无命令替换)拼后缀。 + backup="${config_path}.bak.$$.${RANDOM:-0}" cp "$config_path" "$backup" ui_warn "openclaw.json $reason → 用 template 覆盖(旧文件备份到 $backup)" else