fix(vps-xray): update_env_field 追加时处理缺尾换行的文件,防止字段黏连

This commit is contained in:
2026-08-06 16:08:42 +08:00
parent 39b0aee2c9
commit dfcaf7e4d0
2 changed files with 9 additions and 0 deletions
+4
View File
@@ -139,6 +139,10 @@ update_env_field() {
esc=$(printf '%s' "$value" | sed 's/[|&\\]/\\&/g')
sed -i "s|^${key}=.*|${key}=${esc}|" "$file"
else
# 文件末尾可能缺换行(用户手工编辑过),直接追加会把新字段黏到上一行
if [ -n "$(tail -c 1 "$file")" ]; then
printf '\n' >> "$file"
fi
printf '%s=%s\n' "$key" "$value" >> "$file"
fi
return 0