home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.shell:5255 comp.unix.programmer:5832
- Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!wupost!cs.utexas.edu!sun-barr!news2me.EBay.Sun.COM!jethro.Corp.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: Re: A quoting problem.
- Date: 5 Jan 1993 18:55:44 GMT
- Organization: Sun Microsystems Australia
- Lines: 48
- Distribution: world
- Message-ID: <lkjmdgINN3t2@exodus.Eng.Sun.COM>
- References: <lkh5trINNvf@exodus.Eng.Sun.COM> <1ialduINNe7o@chnews.intel.com>
- NNTP-Posting-Host: stard
- Keywords: SVR4, Bourne shell, quoting filenames.
-
- >In article <lkh5trINNvf@exodus.Eng.Sun.COM> I wrote:
- >>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?
-
- I've had a few replies on this. Thanks to all those people.
-
- From the replies I've received, I believe I should have been clearer. I'm not
- just trying to remove files here. The example was one specific case of a
- generic routine that kicks off all types of commands. I need to run the
- command through "/bin/sh -c command" to expand any possible shell
- meta-characters. Note this is exactly what the system(3) library call does.
-
- Let's turn this into a more specific example. Solving this will hopefully
- show me how to solve the generic case.
- ------
-
- I have three files I want to set the environment variable FILES too:
-
- file a
- file'a
- file"a
-
- What should the string cmd be equal too below in order to get this to work?
-
- char cmd[1024] ;
-
- /* Incorrect version - no quoting. */
-
- strcpy(cmd, "FILES='file a file'a file"a';export FILES;rm $FILES") ;
-
- ...
-
- execl("/bin/sh", "sh", "-c", cmd, (char *) 0) ;
-
- -----
- No solutions suggest unlink and removing the files one at a time please.
- I need a generic solution. I need the correct quoted interpretation of:
-
- FILES='file a file'a file"a'
-
- that correctly works in the string above. Note that people have suggested
- using putenv(3). I'd still have the same quoting problem there.
-
- Thanks again for any help.
-