bash coding: question

David Thornton david-FkEgs2FKm2NvBvnq28/GKQ at public.gmane.org
Fri Oct 3 01:25:38 UTC 2003


This is done much more eloquently with sed:

######### begin Template ##############

FROM THE DESK OF:

@SALUTATION@ @FNAME@ @LNAME@
@RESPECTABLEBUSINESSNAME@
@AFRICANCOUNTRY@

Dear @VICTIM@,


I am @SAL@ @FNAME@ @LNAME@, of @RESPECTABLEBUSINESSNAME@ I have an
urgent and very confidential business proposition for you.

...

######### end Template ##############

populate_bash_vars();

exec sed \
-e "s/@SALUTATION@/$SALUTATION/g" \
-e "s/@FNAME@/$FNAME/g" \
-e "s/@LNAME@/$LNAME/g" \
-e "s/@RESPECTABLEBUSINESSNAME@/$RESPECTABLEBUSINESSNAME/g" \
-e "s/@AFRICANCOUNTRY@/$AFRICANCOUNTRY/g" \
-e "s/@VICTIM@/$VICTIM/g" \
< template | mail -s "an Urgent Matter!" $VICTIMEMAIL

hmm I take that back...

that was not eloquently.

david

----- Original Message ----- 
From: "Peter L. Peres" <plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org>
To: "TLUG" <tlug-lxSQFCZeNF4 at public.gmane.org>
Sent: Friday, August 01, 2003 5:34 PM
Subject: [TLUG]: bash coding: question


>
> Hi,
>
> I am trying to do something impossible (apparently) using bash. I need to
> substitute $var which appears in a file, while using it in a script. I
> have:
>
> > var=1
> > cat file
> This is $var
> > T=`cat $file`
> > echo $T
> This is $var
> > echo `echo $T`
> This is $var
> > echo $var
> 1
>
> How do I make it expand $var ?! I tried just about everything. Admittedly,
> this is a safety feature, but i want to substitute it anyway. I could use
> sed but that is not so nice (there are 1/2 dozen vars to substitute). Any
> ideas ? Besides using Perl instead ?
>
> tia,
>
> Peter
> --
> The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
> TLUG requests: Linux topics, No HTML, wrap text below 80 columns
> How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
>

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list