Assuming the password may contain any character, then no delimiter that you use for the sed
expression is safe to use. If you had, for example, s/.../.../
and the password contained /
, you would have the same issue again.
Therefore, don't use sed
here. Instead,
awk -v pw="$MacAddressPasswordeRegisteryValue" \
'BEGIN { OFS=FS="=" }
$1 == "mac.address.sftp.user.password" { print $1, pw; next } 1' \
"$APP_CONFIG_FILE" >"$APP_CONFIG_FILE"-new
This would transform
mac.address.sftp.user.password=something old
into
mac.address.sftp.user.password=hello world !#$/
given that $MacAddressPasswordeRegisteryValue
was the string hello world !#$/
. Other lines would be passed through unmodified to the new file "$APP_CONFIG_FILE"-new
.
sed “s#foo#${var//#\\#}#”
– Jeff Schaller Apr 19 '18 at 20:15hello\#
. – Kusalananda Apr 19 '18 at 20:17sed
is perfectly fine here as long as the variable is pre-processed (also viased
@JeffSchaller). – don_crissti Apr 19 '18 at 21:58