home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:5263 comp.unix.programmer:5835
- Newsgroups: comp.unix.shell,comp.unix.programmer
- Path: sparky!uunet!cs.utexas.edu!convex!seas.smu.edu!mustafa
- From: mustafa@seas.smu.edu (Mustafa Kocaturk)
- Subject: Re: A quoting problem.
- Message-ID: <1993Jan5.223544.18750@seas.smu.edu>
- Summary: Using escape sequences in Unix and literals in C
- Keywords: SVR4, Bourne shell, quoting filenames.
- Sender: news@seas.smu.edu (USENET News System)
- Nntp-Posting-Host: turbo_f.seas.smu.edu
- Followups-To: comp.lang.c
- Organization: SMU - School of Engineering & Applied Science - Dallas
- References: <lkh5trINNvf@exodus.Eng.Sun.COM> <1ialduINNe7o@chnews.intel.com>
- Date: Tue, 5 Jan 1993 22:35:44 GMT
- Lines: 48
-
- In article <1ialduINNe7o@chnews.intel.com> bhoughto@sedona.intel.com (Blair P. Houghton) writes:
- >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..."
-
- The idea of preceding each character with a backslash does not
- pose a problem as far as the C string interpretation rules are
- concerned: C will interpret escape sequences in literals, and
- only during compilation. The string under consideration is not a
- literal; it is an array filled in by the program while it exe-
- tes. C will never have to interpret that string, except for the
- terminating null character that is interpreted by the execl func-
- tion. (Followups to comp.lang.c)
-
- This leaves you with one less reason for extra backslashes than
- suggested above.
-
-
- Best regards,
-
- Mustafa
- --
- Mustafa Kocaturk mustafa@seas.smu.edu EE Dept., Room 305A, Caruth Bldg.
- Home: 214-706-5954 Office: 214-768-1475 SMU Box 753190, Dallas, TX 75275
-