I am using sed to replace url's in a file, everything works fine just a hiccup when the url contains a '\'
exmaple url: http**://www.example.com/simi/icr
# variables
ICR_KEY=somekey
ICR_KEY_VAL="http\://www.example.com/simi/icr"
sed "s!${ICR_KEY}=.*!${ICR_KEY}=${ICR_KEY_VAL}!" properties > tmp
This replaces the URL, but the output does not contain the backslash from the variable value.
Both bash and sed interpret the backslash as escape character. Use single quotes to prevent this for bash, and double the backslash for sed:
ICR_KEY_VAL='http\\://www.example.com/simi/icr'
来源:https://stackoverflow.com/questions/9487303/escape-backslash-in-variable