mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] match_string: unbound variable (#379)
* [fix] match_string: unbound variable * Define local variables at beginning of function
This commit is contained in:
parent
724f9af923
commit
0086c8c16a
1 changed files with 6 additions and 5 deletions
|
@ -21,7 +21,10 @@ ynh_string_random() {
|
||||||
# references to sub-expressions can be used
|
# references to sub-expressions can be used
|
||||||
# (see sed manual page for more information)
|
# (see sed manual page for more information)
|
||||||
ynh_replace_string () {
|
ynh_replace_string () {
|
||||||
delimit=@
|
local delimit=@
|
||||||
|
local match_string=$1
|
||||||
|
local replace_string=$2
|
||||||
|
local workfile=$3
|
||||||
|
|
||||||
# Escape any backslash to preserve them as simple backslash.
|
# Escape any backslash to preserve them as simple backslash.
|
||||||
match_string=${match_string//\\/"\\\\"}
|
match_string=${match_string//\\/"\\\\"}
|
||||||
|
@ -32,10 +35,8 @@ ynh_replace_string () {
|
||||||
replace_string=${replace_string//&/"\&"}
|
replace_string=${replace_string//&/"\&"}
|
||||||
|
|
||||||
# Escape the delimiter if it's in the string.
|
# Escape the delimiter if it's in the string.
|
||||||
match_string=${1//${delimit}/"\\${delimit}"}
|
match_string=${match_string//${delimit}/"\\${delimit}"}
|
||||||
replace_string=${2//${delimit}/"\\${delimit}"}
|
replace_string=${replace_string//${delimit}/"\\${delimit}"}
|
||||||
|
|
||||||
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