Created
May 14, 2018 09:02
-
-
Save lifeofguenter/5bf05d87ebffda266270871905e5066b to your computer and use it in GitHub Desktop.
env substitution in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tpl::render() { | |
local assign_re='@@([A-Za-z0-9_]+)@@' | |
while IFS='' read -r line || [[ -n "${line}" ]]; do | |
while [[ "${line}" =~ $assign_re ]]; do | |
line="${line/${BASH_REMATCH[0]}/${!BASH_REMATCH[1]}}" | |
done | |
echo "${line}" | |
done < "${1}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment