home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:5239 comp.unix.programmer:5821
- 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
- From: richb@stard.Eng.Sun.COM (Rich Burridge)
- Newsgroups: comp.unix.shell,comp.unix.programmer
- Subject: A quoting problem.
- Date: 4 Jan 1993 20:02:03 GMT
- Organization: Sun Microsystems
- Lines: 32
- Distribution: world
- Message-ID: <lkh5trINNvf@exodus.Eng.Sun.COM>
- NNTP-Posting-Host: stard
- Keywords: SVR4, Bourne shell, quoting filenames.
-
-
- I have a quoting problem. Consider that under UNIX it's possible that
- valid filenames can include:
-
- file
- fi'le
- fi"le
- fi le
- fi`le
- fi*le
-
- plus any combination of any ASCII characters not including a slash '/'
- or a NULL character.
-
- I need to set an environment variable called FILES to a set of such filenames,
- export it, and then run a UNIX command from within a C program. Not handling
- the quoting, this would look something like:
-
- char cmd[1024] ;
-
- strcpy(cmd, "FILES='file file1 file2';export FILES;rm $FILES") ;
-
- ...
-
- execl("/bin/sh", "sh", "-c", cmd, (char *) 0) ;
-
- ...
-
- Now the problem is how to correct quote the "cmd" string to handle all
- possible filenames. Can this be done?
-
- Thanks in advance...
-