Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
env substitution in bash
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