home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:5265 comp.unix.programmer:5836
- Newsgroups: comp.unix.shell,comp.unix.programmer
- Path: sparky!uunet!haven.umd.edu!decuac!pa.dec.com!decprl!decprl!boyd
- From: boyd@prl.dec.com (Boyd Roberts)
- Subject: Re: A quoting problem.
- Message-ID: <1993Jan5.220541.5005@prl.dec.com>
- Keywords: SVR4, Bourne shell, quoting filenames.
- Sender: news@prl.dec.com (USENET News System)
- Nntp-Posting-Host: spooky.prl.dec.com
- Organization: Digital Equipment Corporation - Paris Research Laboratory
- References: <lkh5trINNvf@exodus.Eng.Sun.COM>
- Date: Tue, 5 Jan 1993 22:05:41 GMT
- Lines: 43
-
- In article <lkh5trINNvf@exodus.Eng.Sun.COM>, richb@stard.Eng.Sun.COM (Rich Burridge) writes:
- > 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") ;
- >
-
- Rich, do you really need to do set an environment variable to do this
- particular operation? If you don't then it's trivial to build a sh -c
- style command that goes:
-
- cmd quoted-args
-
- using single quotes.
-
- > execl("/bin/sh", "sh", "-c", cmd, (char *) 0) ;
- >
- > ...
-
- Modulo this '87 Chorey-les-Beaune (Les Beaumonts) the algorithm to quote is:
-
- put down '
-
- while we have chars
- do
- put down char
-
- if char == '
- put down \'
- put down '
- dood
-
- put down '
-
- Then you have a string with multiple quoted arguments.
-
-
- Boyd Roberts boyd@prl.dec.com
-
- ``Not only is UNIX dead, it's starting to smell really bad.'' -- Rob Pike
-