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

Dewey Paciaffi eddjp at edi386.UUCP
Wed Jan 23 01:03:03 AEST 1991


In article <1991Jan21.124531.27867 at siesoft.co.uk> stuart at siesoft.co.uk (Stuart Hood) writes:
>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:
->-
->-I tried:
->-
->-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' ...
-

Point taken.

>which doesn't fall over if "$string" has any whitespace in it.
>
>>Note that you don't want to use the set command to set the variable,
>>and by using the additional single quotes in the sed command, the shell
>>can replace the $string variable.
>
>Why can't you use the set command?

My mistake. There isn't any reason you can't when using the csh, as many have 
pointed out to me since. 



-- 
Dewey Paciaffi           ...!uunet!edi386!eddjp



More information about the Comp.unix.shell mailing list