Skip to content

Instantly share code, notes, and snippets.

@sfgeorge
Created February 18, 2020 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfgeorge/b08e510c77fd36009d85a5d91743fa24 to your computer and use it in GitHub Desktop.
Save sfgeorge/b08e510c77fd36009d85a5d91743fa24 to your computer and use it in GitHub Desktop.
Simple UNIX templating with the printf command
# Create a template
echo 'I am just a lowly %s,
playing with %s and %s,
dancing in a %s and trying not to get %s.' > jolly.template
# Evaluate the template
printf "$(<jolly.template)" scoundrel sticks 'barbed wire' web caught
# Or Evaluate the template and silently set it to a shell variable
printf -v output "$(<jolly.template)" scoundrel sticks 'barbed wire' web caught
echo "$output"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment