I have the default main template "template_in.txt" and additionally several License.txt templates. Based on a environment variable, I want to concatenate the license with the main template, but I don't know how
this is the default command to insert a template:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%Y-%m-%d` \ TM_USERNAME=`niutil -readprop / /users/$USER realname` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' \ < template_in.txt > "$TM_NEW_FILE" fi
I tried to to turn it into somethng like this:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%Y-%m-%d` \ TM_USERNAME=`niutil -readprop / /users/$USER realname` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' \ < template_in.txt << License.txt > "$TM_NEW_FILE" fi
unfortunately this doesn't work.
Anybody an idea how I can make this work ?
regards
On 11 Nov 2007, at 03:49, Roberto Saccon wrote:
[...] I tried to to turn it into somethng like this:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%Y-%m-%d` \ TM_USERNAME=`niutil -readprop / /users/$USER realname` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' \ < template_in.txt << License.txt > "$TM_NEW_FILE" fi
Try this instead:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%Y-%m-%d` \ cat template_in.txt License.txt \ |perl -pe 's/${([^}]*)}/$ENV{$1}/g' > "$TM_NEW_FILE" fi
Here we use ‘cat’ to actually con_cat_enate two files, must be a first ;)
Note I also removed the setup of TM_USERNAME -- we now have TM_FULLNAME as a “built-in” since relying on niutil or similar was too fragile, but I forgot to update the template for the New Template.
thanks, concatenating now works great, but the variables TM_YEAR and TM_DATE don't get passed anymore to the template !!
On Nov 11, 2007 5:54 AM, Allan Odgaard throw-away-2@macromates.com wrote:
On 11 Nov 2007, at 03:49, Roberto Saccon wrote:
[...] I tried to to turn it into somethng like this:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%Y-%m-%d` \ TM_USERNAME=`niutil -readprop / /users/$USER realname` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' \ < template_in.txt << License.txt > "$TM_NEW_FILE" fi
Try this instead:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%Y-%m-%d` \ cat template_in.txt License.txt \ |perl -pe 's/\$\{([^}]*)\}/$ENV{$1}/g' > "$TM_NEW_FILE" fi
Here we use 'cat' to actually con_cat_enate two files, must be a first ;)
Note I also removed the setup of TM_USERNAME -- we now have TM_FULLNAME as a "built-in" since relying on niutil or similar was too fragile, but I forgot to update the template for the New Template.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On 11 Nov 2007, at 13:18, Roberto Saccon wrote:
thanks, concatenating now works great, but the variables TM_YEAR and TM_DATE don't get passed anymore to the template !!
Ah, because they now get set for “cat” rather than “perl”.
So this would be a way to set them for “perl” instead:
if [[ ! -f "$TM_NEW_FILE" ]]; then cat template_in.txt License.txt \ |TM_YEAR=`date +%Y` TM_DATE=`date +%Y-%m-%d` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' > "$TM_NEW_FILE" fi
A perhaps simpler approach is to export them (to all commands):
if [[ ! -f "$TM_NEW_FILE" ]]; then export TM_YEAR=`date +%Y` export TM_DATE=`date +%Y-%m-%d` cat template_in.txt License.txt \ |perl -pe 's/${([^}]*)}/$ENV{$1}/g' > "$TM_NEW_FILE" fi