Skip to content

Instantly share code, notes, and snippets.

@DonMartin76 DonMartin76/template.sh
Last active Mar 2, 2017

Embed
What would you like to do?
Quick, ugly, efficient bash script for templating files - takes everything ending with .template and replaces env vars inside them
#!/bin/bash
for tmpl in $(find . | grep '\.template'); do
targetFile=${tmpl%.*}
echo "Templating ${tmpl} to ${targetFile}..."
perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' $tmpl > $targetFile
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.