home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / shell / 5239 < prev    next >
Encoding:
Text File  |  1993-01-04  |  1.2 KB  |  46 lines

  1. Xref: sparky comp.unix.shell:5239 comp.unix.programmer:5821
  2. Path: sparky!uunet!spool.mu.edu!wupost!cs.utexas.edu!sun-barr!male.EBay.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: A quoting problem.
  6. Date: 4 Jan 1993 20:02:03 GMT
  7. Organization: Sun Microsystems
  8. Lines: 32
  9. Distribution: world
  10. Message-ID: <lkh5trINNvf@exodus.Eng.Sun.COM>
  11. NNTP-Posting-Host: stard
  12. Keywords: SVR4, Bourne shell, quoting filenames.
  13.  
  14.  
  15. I have a quoting problem. Consider that under UNIX it's possible that
  16. valid filenames can include:
  17.  
  18. file
  19. fi'le
  20. fi"le
  21. fi le
  22. fi`le
  23. fi*le
  24.  
  25. plus any combination of any ASCII characters not including a slash '/'
  26. or a NULL character.
  27.  
  28. I need to set an environment variable called FILES to a set of such filenames,
  29. export it, and then run a UNIX command from within a C program. Not handling
  30. the quoting, this would look something like:
  31.  
  32. char cmd[1024] ;
  33.  
  34. strcpy(cmd, "FILES='file file1 file2';export FILES;rm $FILES") ;
  35.  
  36. ...
  37.  
  38. execl("/bin/sh", "sh", "-c", cmd, (char *) 0) ;
  39.  
  40. ...
  41.  
  42. Now the problem is how to correct quote the "cmd" string to handle all
  43. possible filenames. Can this be done?
  44.  
  45. Thanks in advance...
  46.