sed 's/foobar/$string/g'.... can't do this?

Brandon S. Allbery KB8JRR allbery at NCoast.ORG
Wed Jan 23 15:44:06 AEST 1991


As quoted from <1991Jan21.124531.27867 at siesoft.co.uk> by stuart at siesoft.co.uk (Stuart Hood):
+---------------
| eddjp at edi386.UUCP ( Dewey Paciaffi ) writes:
| >In article <1991Jan17.003856.469 at unicorn.cc.wwu.edu> n8743196 at unicorn.cc.wwu.edu (Jeff Wandling) writes:
| >-set string = newfoobar
| >-cat file | sed 's/foobar/$string/g' ....
| 
| >You might try this :
| >	string=newfoobar
| >	cat file | sed 's/foobar/'$string'/g' ...
| 
| Small point, to be safe you should do:
| cat file | sed 's/foobar/'"$string"'/g' ...
| 
| >Note that you don't want to use the set command to set the variable,
| Why can't you use the set command?
+---------------

"Cultural differences".  In csh, you *must* use "set"; in Bourne shell, you
must *not* use it.

As long as we're nit-picking:  it's faster to say

	string=newfoobar # csh: set string = newfoobar
	sed 's/foobar/'"$string"'/g' < file

because you don't have to start the "cat".

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery at NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY



More information about the Comp.unix.shell mailing list