mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Escape some special character in ynh_replace_string
This commit is contained in:
parent
32d3a9940b
commit
bb2424e9b8
1 changed files with 11 additions and 1 deletions
|
@ -18,8 +18,18 @@ ynh_string_random() {
|
||||||
# | arg: target_file - File in which the string will be replaced.
|
# | arg: target_file - File in which the string will be replaced.
|
||||||
ynh_replace_string () {
|
ynh_replace_string () {
|
||||||
delimit=@
|
delimit=@
|
||||||
match_string=${1//${delimit}/"\\${delimit}"} # Escape the delimiter if it's in the string.
|
# Escape the delimiter if it's in the string.
|
||||||
|
match_string=${1//${delimit}/"\\${delimit}"}
|
||||||
replace_string=${2//${delimit}/"\\${delimit}"}
|
replace_string=${2//${delimit}/"\\${delimit}"}
|
||||||
|
|
||||||
|
# Escape any backslash to preserve them as simple backslash.
|
||||||
|
match_string=${match_string//\\/"\\\\"}
|
||||||
|
replace_string=${replace_string//\\/"\\\\"}
|
||||||
|
|
||||||
|
# Escape the & character, who has a special function in sed.
|
||||||
|
match_string=${match_string//&/"\&"}
|
||||||
|
replace_string=${replace_string//&/"\&"}
|
||||||
|
|
||||||
workfile=$3
|
workfile=$3
|
||||||
|
|
||||||
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"
|
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"
|
||||||
|
|
Loading…
Add table
Reference in a new issue