home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / shell / 5265 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  1.6 KB

  1. Xref: sparky comp.unix.shell:5265 comp.unix.programmer:5836
  2. Newsgroups: comp.unix.shell,comp.unix.programmer
  3. Path: sparky!uunet!haven.umd.edu!decuac!pa.dec.com!decprl!decprl!boyd
  4. From: boyd@prl.dec.com (Boyd Roberts)
  5. Subject: Re: A quoting problem.
  6. Message-ID: <1993Jan5.220541.5005@prl.dec.com>
  7. Keywords: SVR4, Bourne shell, quoting filenames.
  8. Sender: news@prl.dec.com (USENET News System)
  9. Nntp-Posting-Host: spooky.prl.dec.com
  10. Organization: Digital Equipment Corporation - Paris Research Laboratory
  11. References:  <lkh5trINNvf@exodus.Eng.Sun.COM>
  12. Date: Tue, 5 Jan 1993 22:05:41 GMT
  13. Lines: 43
  14.  
  15. In article <lkh5trINNvf@exodus.Eng.Sun.COM>, richb@stard.Eng.Sun.COM (Rich Burridge) writes:
  16. > I need to set an environment variable called FILES to a set of such filenames,
  17. > export it, and then run a UNIX command from within a C program. Not handling
  18. > the quoting, this would look something like:
  19. > char cmd[1024] ;
  20. > strcpy(cmd, "FILES='file file1 file2';export FILES;rm $FILES") ;
  21.  
  22. Rich, do you really need to do set an environment variable to do this
  23. particular operation?  If you don't then it's trivial to build a sh -c
  24. style command that goes:
  25.  
  26.     cmd quoted-args
  27.  
  28. using single quotes.
  29.  
  30. > execl("/bin/sh", "sh", "-c", cmd, (char *) 0) ;
  31. > ...
  32.  
  33. Modulo this '87 Chorey-les-Beaune (Les Beaumonts) the algorithm to quote is:
  34.  
  35.    put down '
  36.  
  37.    while we have chars
  38.    do
  39.        put down char
  40.  
  41.        if char == '
  42.            put down \'
  43.            put down '
  44.    dood
  45.  
  46.    put down '
  47.  
  48. Then you have a string with multiple quoted arguments.
  49.  
  50.  
  51. Boyd Roberts            boyd@prl.dec.com
  52.  
  53. ``Not only is UNIX dead, it's starting to smell really bad.''  -- Rob Pike
  54.