0

I'm getting a syntax error when running sed in my bash script. Non of the similar issues on here have resolved my problem.

I need to update a line in a config for a VPN connection.

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

Line in file "auth-user-pass" should found and replaced with "auth-user-pass ../login.conf". I'm unable to get passed the syntax error: sed: -e expression #1, char [#]: unterminated `s' command

1 Answers1

0

Sed can use almost any character as its 'delimiter'. You're having trouble because your chosen delimiter / appears in your variable.

sed -i.bak "s,$auth,$update" $serverconfig

You can also perform this substitution as many times as possible with the global operation:

sed -i.back "s,$auth,$update,g" $serverconfig
vintnes
  • 2,014
  • 7
  • 16