以下ではsedコマンドを使用していますが、ifはbuildとdeleteMacAddressPasswordeRegisteryValue
です。これを避ける方法はありますか?WElcome12#
WElcome12
#
sed -i "s#^mac.address.sftp.user.password=.*#mac.address.sftp.user.password=${MacAddressPasswordeRegisteryValue#*=}#" $APP_CONFIG_FILE
ベストアンサー1
パスワードに文字を含めることができると仮定すると、式で使用されている区切り文字はsed
安全には使用できません。たとえば、s/.../.../
パスワードにが含まれている場合、/
同じ問題が再発生します。
したがって、sed
ここでは使用しないでください。代わりに、
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
これは変わるでしょう
mac.address.sftp.user.password=something old
入力する
mac.address.sftp.user.password=hello world !#$/
それが$MacAddressPasswordeRegisteryValue
文字列であればhello world !#$/
。他の行は変更なしで新しいファイルに渡されます"$APP_CONFIG_FILE"-new
。