TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:10363] Using sed and evironmental variables



On Mon, Nov 22, 1999 at 03:55:37PM -0600, Bob Tanner wrote:
> Is there a way to pass environmental variables into a sed script?
> 
> I have a env var called FOO=bob and the following sed script:
> 
> cat file | sed -e 's/FOO/$FOO/g'
> 
> I want to replace all occurances of "FOO" in file "file" with the value of the
> environmental variable FOO, which has a value of bob.
> 
> Using the above sed script, all occurances of "FOO" are replaced by "$FOO",
> not the bob (the value of $FOO).

	You could try:

cat file | sed -e "s/FOO/$FOO/g"

	Of course, if $FOO contains any '/'s or '\'s you still have
problems.

Have fun (if at all possible),
-- 
Its name is Public Opinion.  It is held in reverence. It settles everything.
Some think it is the voice of God.  Loyalty to petrified opinion never yet
broke a chain or freed a human soul.     ---Mark Twain
-- Eric Hopper (hopper@omnifarious.mn.org
                http://ehopper-host105.dsl.visi.com/~hopper) --