Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Last active December 12, 2015 12:19
Show Gist options
  • Save thinkerbot/4771037 to your computer and use it in GitHub Desktop.
Save thinkerbot/4771037 to your computer and use it in GitHub Desktop.
interpolate () {
eval "
sed -e 's/^://' <<TEMPLATE
$(sed -e 's/^/:/' -e 's/\([`\]\)/\\\1/g' -e 's/$(/\\$(/g')
TEMPLATE
"
}
item=milk
cat <<<'got $item'
interpolate <<<'got $item'
hello `$thing`
hello $($thing)
hello \`$thing\`
hello $\($thing\)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment