Last active
March 2, 2017 15:55
-
-
Save DonMartin76/cde753ec188b92f526e1a8d1c9b5caae to your computer and use it in GitHub Desktop.
Quick, ugly, efficient bash script for templating files - takes everything ending with .template and replaces env vars inside them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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