home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!mel.dit.csiro.au!yarra!kenj
- From: kenj@yarra.pyramid.com.au (Ken McDonell)
- Newsgroups: comp.unix.shell
- Subject: Re: Sed with shell variables
- Message-ID: <79655@yarra.pyramid.com.au>
- Date: 20 Aug 92 23:09:34 GMT
- References: <2701@nlsun1.oracle.nl> <1992Aug20.105737.29473@ccu1.aukuni.ac.nz>
- Organization: Pyramid Technology Corp PL, Melb., Australia
- Lines: 29
-
- ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig) writes:
-
- >rgasch@nl.oracle.com (Robert Gasch) writes:
-
- >>The problem I ran into is that I can't get shell variables to
- >>work as arguments. When I type
- >> echo $something|sed 's/$this_pattern_var/$that_pattern_var/'
-
- >>sed throws up on me. I've tried various combinations of quotation
- >>marks without success. Is there an easy way of doing this??
-
- >echo $something | sed -e s/$this_pattern/$that_pattern/
-
- It is generally safer to use something like ...
-
- echo "$something" | sed -e "s/$this_pattern/$that_pattern/"
-
- unless you can be certain that the variables something, this_pattern and
- that_pattern
- - do not contain white space, and
- - do not contain meta characters (e.g. * [ ?)
-
- Of course, if this_pattern and/or that_pattern contain the character /
- then one needs to resort to something even more obtuse!
- --
- Ken McDonell E-mail: kenj@pyramid.com
- Systems Technology Laboratory kenj@yarra.pyramid.com.au
- Pyramid Technology Corporation Phone: +61 3 521 3799
- Melbourne, Australia Disclaimer: I speak for me alone, of course.
-