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

  1. Xref: sparky comp.unix.shell:5255 comp.unix.programmer:5832
  2. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!wupost!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!jethro.Corp.Sun.COM!exodus.Eng.Sun.COM!stard.Eng.Sun.COM!richb
  3. From: richb@stard.Eng.Sun.COM (Rich Burridge)
  4. Newsgroups: comp.unix.shell,comp.unix.programmer
  5. Subject: Re: A quoting problem.
  6. Date: 5 Jan 1993 18:55:44 GMT
  7. Organization: Sun Microsystems Australia
  8. Lines: 48
  9. Distribution: world
  10. Message-ID: <lkjmdgINN3t2@exodus.Eng.Sun.COM>
  11. References: <lkh5trINNvf@exodus.Eng.Sun.COM> <1ialduINNe7o@chnews.intel.com>
  12. NNTP-Posting-Host: stard
  13. Keywords: SVR4, Bourne shell, quoting filenames.
  14.  
  15. >In article <lkh5trINNvf@exodus.Eng.Sun.COM> I wrote:
  16. >>strcpy(cmd, "FILES='file file1 file2';export FILES;rm $FILES") ;
  17. >>...
  18. >>execl("/bin/sh", "sh", "-c", cmd, (char *) 0) ;
  19. >>...
  20. >>Now the problem is how to correct quote the "cmd" string to handle all
  21. >>possible filenames. Can this be done?
  22.  
  23. I've had a few replies on this. Thanks to all those people.
  24.  
  25. From the replies I've received, I believe I should have been clearer. I'm not
  26. just trying to remove files here. The example was one specific case of a
  27. generic routine that kicks off all types of commands. I need to run the
  28. command through "/bin/sh -c command" to expand any possible shell
  29. meta-characters.  Note this is exactly what the system(3) library call does.
  30.  
  31. Let's turn this into a more specific example. Solving this will hopefully
  32. show me how to solve the generic case.
  33. ------
  34.  
  35. I have three files I want to set the environment variable FILES too:
  36.  
  37. file a
  38. file'a
  39. file"a
  40.  
  41. What should the string cmd be equal too below in order to get this to work?
  42.  
  43. char cmd[1024] ;
  44.  
  45. /*  Incorrect version - no quoting. */
  46.  
  47. strcpy(cmd, "FILES='file a file'a file"a';export FILES;rm $FILES") ;
  48.  
  49. ...
  50.  
  51. execl("/bin/sh", "sh", "-c", cmd, (char *) 0) ;
  52.  
  53. -----
  54. No solutions suggest unlink and removing the files one at a time please.
  55. I need a generic solution. I need the correct quoted interpretation of:
  56.  
  57. FILES='file a file'a file"a'
  58.  
  59. that correctly works in the string above. Note that people have suggested
  60. using putenv(3). I'd still have the same quoting problem there.
  61.  
  62. Thanks again for any help.
  63.