Skip to content

Instantly share code, notes, and snippets.

@DonMartin76 DonMartin76/

Last active Mar 2, 2017
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
for tmpl in $(find . | grep '\.template'); do
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
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.