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