Fix double backslash in case of delimiter used

This commit is contained in:
Maniack Crudelis 2017-10-03 22:11:24 +02:00 committed by GitHub
parent bb2424e9b8
commit e3a4b307f7

View file

@ -18,9 +18,6 @@ ynh_string_random() {
# | arg: target_file - File in which the string will be replaced.
ynh_replace_string () {
delimit=@
# Escape the delimiter if it's in the string.
match_string=${1//${delimit}/"\\${delimit}"}
replace_string=${2//${delimit}/"\\${delimit}"}
# Escape any backslash to preserve them as simple backslash.
match_string=${match_string//\\/"\\\\"}
@ -30,6 +27,10 @@ ynh_replace_string () {
match_string=${match_string//&/"\&"}
replace_string=${replace_string//&/"\&"}
# Escape the delimiter if it's in the string.
match_string=${1//${delimit}/"\\${delimit}"}
replace_string=${2//${delimit}/"\\${delimit}"}
workfile=$3
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"