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

  1. Xref: sparky comp.unix.shell:5244 comp.unix.programmer:5824
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!asuvax!chnews!sedona!bhoughto
  3. From: bhoughto@sedona.intel.com (Blair P. Houghton)
  4. Newsgroups: comp.unix.shell,comp.unix.programmer
  5. Subject: Re: A quoting problem.
  6. Date: 5 Jan 1993 00:40:30 GMT
  7. Organization: Intel Corp., Chandler, Arizona
  8. Lines: 27
  9. Distribution: world
  10. Message-ID: <1ialduINNe7o@chnews.intel.com>
  11. References: <lkh5trINNvf@exodus.Eng.Sun.COM>
  12. NNTP-Posting-Host: stealth.intel.com
  13. Keywords: SVR4, Bourne shell, quoting filenames.
  14.  
  15. In article <lkh5trINNvf@exodus.Eng.Sun.COM> richb@stard.Eng.Sun.COM (Rich Burridge) writes:
  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. Not trivially.
  24.  
  25. Since you're sending the output to the shell your program
  26. has to be as smart as you would have been had you typed the
  27. command-line to the shell yourself.
  28.  
  29. That is, the program would have to put a backslash in all
  30. the proper places in filenames that require escaped characters.
  31.  
  32. The simplest way to do this would be to put a backslash in
  33. front of every character, but you then conflict with C's
  34. interpretation of certain escape sequences within strings
  35. (e.g., "\n" and "\"").
  36.  
  37. That is, sometimes it takes two backslashes, sometimes one,
  38. but most of the time none.
  39.  
  40.                 --Blair
  41.                   "That depends..."
  42.