【发布时间】:2019-10-13 08:49:27
【问题描述】:
在我的 bash 脚本中运行 sed 时出现语法错误。这里没有类似的问题解决了我的问题。
我需要为 VPN 连接更新配置中的一行。
serverconfig='vpnsrv.tcp.ovpn'
auth='auth-user-pass'
update='../login.conf'
sed -i.bak "s/$auth/$update" $serverconfig
# I have also tried these:
#sed -i.bak 's/auth-user-pass/auth-user-pass "${update}"' $serverconfig
#sed -i.bak 's/auth-user-pass/auth-user-pass '"${update}"'' $serverconfig
#sed -i.bak 's/auth-user-pass/auth-user-pass\ "${update}"' $serverconfig
#sed -i.bak 's/auth-user-pass/auth-user-pass\ "$update"' $serverconfig
#sed -i.bak 's/'"$auth"'/'"$auth $update"' $serverconfig
# sed: -e expression #1, char 32: unterminated `s' command
应该找到文件“auth-user-pass”中的行并将其替换为“auth-user-pass ../login.conf”。我无法通过语法错误:sed: -e expression #1, char [#]: unterminated `s' command
【问题讨论】:
-
尝试更改分隔符
-
你只需要一个斜杠:
sed -i.bak "s/$auth/$update/" $serverconfig -
我得到了
sed: -e expression #1, char 32: unterminateds 命令`:sed -i.bak "s/$auth/$update/" $serverconfig