home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3554 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  1.5 KB

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