Skip to content

Commit 24d431c

Browse files
authored
Merge pull request #6 from francisek/wip/better-shell-expansion
better variable substitution
2 parents 180f0d3 + 2565370 commit 24d431c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/core.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,19 @@ php_band_parse_version() {
5555
# utilities
5656
php_band_apply_shell_expansion() {
5757
declare data=$1
58+
declare PHP_BAND_DOLLAR='$'
5859
declare delimiter="__apply_shell_expansion_delimiter__"
5960
declare command="cat <<$delimiter"$'\n'"$data"$'\n'"$delimiter"
6061
eval "$command"
6162
}
6263

63-
# Subst {{varname}} with ${varname}}
64+
# Subst {{varname}} with ${varname}
6465
# If no variable with that name exists, the placeholder is substed with empty string
6566
php_band_substitute() {
6667
local filename="$1"
6768
local v
68-
v=$(sed -r -e "s/\{\{([^\}]+)\}\}/\${\1}/g" "$filename")
69+
sed -r -i -e "s/\\\$/\${PHP_BAND_DOLLAR}/g" "${filename}"
70+
v=$(sed -r -e "s/\{\{([^\}]+)\}\}/\${\1:-}/g" "${filename}")
6971
v=$(php_band_apply_shell_expansion "$v")
7072
echo "$v" > "$filename"
7173
}

0 commit comments

Comments
 (0)