makeWrapper: quote values properly
This uses Bash ${foo@Q} feature to quote values properly, which allows us to handle values containing spaces, dollars etc. Thanks orivej for the idea!
This commit is contained in:
parent
304259bdb1
commit
29c0591dc1
@ -47,7 +47,7 @@ makeWrapper() {
|
|||||||
varName="${params[$((n + 1))]}"
|
varName="${params[$((n + 1))]}"
|
||||||
value="${params[$((n + 2))]}"
|
value="${params[$((n + 2))]}"
|
||||||
n=$((n + 2))
|
n=$((n + 2))
|
||||||
echo "export $varName=\"$value\"" >> "$wrapper"
|
echo "export $varName=${value@Q}" >> "$wrapper"
|
||||||
elif [[ "$p" == "--unset" ]]; then
|
elif [[ "$p" == "--unset" ]]; then
|
||||||
varName="${params[$((n + 1))]}"
|
varName="${params[$((n + 1))]}"
|
||||||
n=$((n + 1))
|
n=$((n + 1))
|
||||||
@ -63,9 +63,9 @@ makeWrapper() {
|
|||||||
n=$((n + 3))
|
n=$((n + 3))
|
||||||
if test -n "$value"; then
|
if test -n "$value"; then
|
||||||
if test "$p" = "--suffix"; then
|
if test "$p" = "--suffix"; then
|
||||||
echo "export $varName=\$$varName\${$varName:+$separator}$value" >> "$wrapper"
|
echo "export $varName=\$$varName\${$varName:+${separator@Q}}${value@Q}" >> "$wrapper"
|
||||||
else
|
else
|
||||||
echo "export $varName=$value\${$varName:+$separator}\$$varName" >> "$wrapper"
|
echo "export $varName=${value@Q}\${$varName:+${separator@Q}}\$$varName" >> "$wrapper"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [[ "$p" == "--suffix-each" ]]; then
|
elif [[ "$p" == "--suffix-each" ]]; then
|
||||||
@ -74,7 +74,7 @@ makeWrapper() {
|
|||||||
values="${params[$((n + 3))]}"
|
values="${params[$((n + 3))]}"
|
||||||
n=$((n + 3))
|
n=$((n + 3))
|
||||||
for value in $values; do
|
for value in $values; do
|
||||||
echo "export $varName=\$$varName\${$varName:+$separator}$value" >> "$wrapper"
|
echo "export $varName=\$$varName\${$varName:+$separator}${value@Q}" >> "$wrapper"
|
||||||
done
|
done
|
||||||
elif [[ ("$p" == "--suffix-contents") || ("$p" == "--prefix-contents") ]]; then
|
elif [[ ("$p" == "--suffix-contents") || ("$p" == "--prefix-contents") ]]; then
|
||||||
varName="${params[$((n + 1))]}"
|
varName="${params[$((n + 1))]}"
|
||||||
@ -82,10 +82,11 @@ makeWrapper() {
|
|||||||
fileNames="${params[$((n + 3))]}"
|
fileNames="${params[$((n + 3))]}"
|
||||||
n=$((n + 3))
|
n=$((n + 3))
|
||||||
for fileName in $fileNames; do
|
for fileName in $fileNames; do
|
||||||
|
contents="$(cat "$fileName")"
|
||||||
if test "$p" = "--suffix-contents"; then
|
if test "$p" = "--suffix-contents"; then
|
||||||
echo "export $varName=\$$varName\${$varName:+$separator}$(cat "$fileName")" >> "$wrapper"
|
echo "export $varName=\$$varName\${$varName:+$separator}${contents@Q}" >> "$wrapper"
|
||||||
else
|
else
|
||||||
echo "export $varName=$(cat "$fileName")\${$varName:+$separator}\$$varName" >> "$wrapper"
|
echo "export $varName=${contents@Q}\${$varName:+$separator}\$$varName" >> "$wrapper"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
elif [[ "$p" == "--add-flags" ]]; then
|
elif [[ "$p" == "--add-flags" ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user