mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Fix broken ynh_replace_string (#394)
* Fix broken ynh_replace_string * Replace name for ynh_replace_special_string
This commit is contained in:
parent
1c367895b0
commit
542528ab05
1 changed files with 22 additions and 5 deletions
|
@ -26,6 +26,27 @@ ynh_replace_string () {
|
|||
local replace_string=$2
|
||||
local workfile=$3
|
||||
|
||||
# Escape the delimiter if it's in the string.
|
||||
match_string=${match_string//${delimit}/"\\${delimit}"}
|
||||
replace_string=${replace_string//${delimit}/"\\${delimit}"}
|
||||
|
||||
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"
|
||||
}
|
||||
|
||||
# Substitute/replace a special string by another in a file
|
||||
#
|
||||
# usage: ynh_replace_special_string match_string replace_string target_file
|
||||
# | arg: match_string - String to be searched and replaced in the file
|
||||
# | arg: replace_string - String that will replace matches
|
||||
# | arg: target_file - File in which the string will be replaced.
|
||||
#
|
||||
# This helper will use ynh_replace_string, but as you can use special
|
||||
# characters, you can't use some regular expressions and sub-expressions.
|
||||
ynh_replace_special_string () {
|
||||
local match_string=$1
|
||||
local replace_string=$2
|
||||
local workfile=$3
|
||||
|
||||
# Escape any backslash to preserve them as simple backslash.
|
||||
match_string=${match_string//\\/"\\\\"}
|
||||
replace_string=${replace_string//\\/"\\\\"}
|
||||
|
@ -34,9 +55,5 @@ ynh_replace_string () {
|
|||
match_string=${match_string//&/"\&"}
|
||||
replace_string=${replace_string//&/"\&"}
|
||||
|
||||
# Escape the delimiter if it's in the string.
|
||||
match_string=${match_string//${delimit}/"\\${delimit}"}
|
||||
replace_string=${replace_string//${delimit}/"\\${delimit}"}
|
||||
|
||||
sudo sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}g" "$workfile"
|
||||
ynh_replace_string "$match_string" "$replace_string" "$workfile"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue