Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lifeofguenter/5bf05d87ebffda266270871905e5066b to your computer and use it in GitHub Desktop.
Save lifeofguenter/5bf05d87ebffda266270871905e5066b to your computer and use it in GitHub Desktop.
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