mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-05-22 01:37:37 +00:00
templater.sh: use perl if available (#98)
This commit is contained in:
parent
f57e37eb68
commit
ee869a9584
@ -39,12 +39,17 @@ function templater() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$(command -v perl)" ]]; then
|
||||
perl -p -e 's/\$\{(\w+)\}/(exists $ENV{$1} ? $ENV{$1} : "\${$1}")/eg' < "${templateSrc}" > "${templateDst}"
|
||||
else
|
||||
cp -f "${templateSrc}" "${templateDst}"
|
||||
|
||||
for var in $(env |awk -F= '{print $1}' |grep -E '^(_[A-Z0-9_]+|[A-Z0-9][A-Z0-9_]*)$'); do
|
||||
sed -i.bak -e "s#\${${var}}#${!var//#/\\#/}#g" "${templateDst}"
|
||||
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
|
||||
rm -f "${templateDst}.bak"
|
||||
done
|
||||
fi
|
||||
|
||||
# cat "${templateDst}"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user