From 76f9640a4f81c2a97ea33f1d14db5a8dae103200 Mon Sep 17 00:00:00 2001 From: huangbinghe Date: Thu, 23 Jul 2026 10:42:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(dev):=20nc=20=E5=85=BC=E5=AE=B9BSD=20netcat?= =?UTF-8?q?=20(#2205)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(dev): nc 兼容BSD netcat --- scripts/dev.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/dev.sh b/scripts/dev.sh index a3721b7f..4ad48d84 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -86,11 +86,17 @@ show_help() { } # 加载 .env 与可选的 .env.local(后者覆盖前者) +# 读取 .env 时去掉行尾的 \r,兼容 Windows 风格(CRLF)换行符, +# 否则 bash source 会把残留的 \r 当成命令导致 "...: $'\r': command not found"。 +_clean_env_file() { + sed -e 's/\r$//' "$1" +} + load_env_files() { if [ -f ".env" ]; then set -a # shellcheck source=/dev/null - source .env + source <(_clean_env_file .env) set +a else return 1 @@ -100,7 +106,7 @@ load_env_files() { log_info "加载 .env.local 覆盖配置..." set -a # shellcheck source=/dev/null - source .env.local + source <(_clean_env_file .env.local) set +a fi return 0 @@ -372,7 +378,7 @@ check_remote_dev_connectivity() { local h="${rest%%:*}" local p="${rest##*:}" if command -v nc &> /dev/null; then - if nc -z -G 3 "$h" "$p" 2>/dev/null; then + if nc -z -w 3 "$h" "$p" 2>/dev/null; then log_success "${name} ${h}:${p} 可达" else log_error "${name} ${h}:${p} 不可达 (no route / connection refused)"