From: "Arthur J. O'Dwyer" Newsgroups: comp.os.msdos.djgpp Subject: Re: Bug in command-line globbing Date: Fri, 13 Dec 2002 12:26:14 -0500 (EST) Organization: Carnegie Mellon, Pittsburgh, PA Lines: 87 Message-ID: NNTP-Posting-Host: smtp5.andrew.cmu.edu Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: bb3.andrew.cmu.edu 1039800374 16047 128.2.10.85 (13 Dec 2002 17:26:14 GMT) X-Complaints-To: advisor AT andrew DOT cmu DOT edu NNTP-Posting-Date: 13 Dec 2002 17:26:14 GMT In-Reply-To: <4634-Fri13Dec2002111638+0200-eliz@is.elta.co.il> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Fri, 13 Dec 2002, Eli Zaretskii wrote: > > > From: "Arthur J. O'Dwyer" > > Newsgroups: comp.os.msdos.djgpp > > Date: Thu, 12 Dec 2002 22:29:02 -0500 (EST) > > > > Notice that the "globbing" doesn't complain about mismatched quotes, > > and makes some argument values impossible to construct. > > Examples, please! Some cases of mismatched quotes are actually the > shell's fault. In any case, DJGPP behaves like DOS/Windows programs: > they don't generally complain about mismatched quotes. True. On the other hand, DJGPP behaves like Unix programs: they generally perform filename globbing. So when I want a literal * or ? in my argument list, I have to use quotes. In DOS, I hardly ever use quotes, because they're not needed except for including whitespace in an argument (which is rarely useful, IME). So when I use quotes, I am usually in my mental "Unix mode", and I expect the quotes to behave as closely to Unix as possible. Wht do you mean, "Some cases of mismatched quotes are actually the shell's fault"? How much globbing (by which I mean generic "argument parsing") is done by the shell (by which I mean COMMAND.COM)? My experience from assembler programming is that COMMAND.COM doesn't do any parsing of arguments at all; it's entirely up to the client. > > Hence, I suggest that it is broken by design. > > I think you are mistaken, but please feel free to explain why you > think it's broken. Specific examples will probably help. My original example was (essentially) trying to get the following test to execute successfully: int main (int argc, char **argv) { if (strcmp("*\\", argv[1])==0 && strcmp("hello", argv[2])==0) { printf("Good!\n"); } } You need to quote the * character, but you can't quote the \ character because it will try to escape the closing quote, producing *" or *'. A. Sinan Unur points out that % test.exe "*"\ hello works, but it looks like an incredibly flimsy hack to me, and I wouldn't be surprised if it stopped working in future versions of DJGPP (because the next guy who looks at the globbing code might not know this hack is out there). What I really want is to design a 'tr'-like program which takes as arguments a list of hyphen-options, followed by one or two regexes, followed optionally by a (list of) filename(s). tr [ -cds ] string1 [ string2 ] [ filename ] Inside the regexes, I'd like \ to be an escape character, for example, to specify the deletion of periods, question marks, and backslashes from all text files in the current directory one could write: tr -d .?\\ *.txt where the first \ escapes the second \. Unfortunately, without quotes the first argument globs to a list of directory names, with quotes it globs to .?\" or .?\', and if I turn off globbing altogether then the second argument does not expand. In bash or ksh (as the nice folks in comp.unix.misc have informed me), the following command line does what I want: tr -d '.?\\' *.txt With DJGPP in MS-DOS, the best I can do is tr -d ".?"\ *.txt and I've already explained that this just looks bad. Thanks, -Arthur