www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/12/13/18:45:41

From: "A. Sinan Unur" <asu1 AT c-o-r-n-e-l-l DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bug in command-line globbing
Date: 13 Dec 2002 23:33:10 GMT
Organization: Cornell University
Lines: 60
Sender: asu1 AT cornell DOT invalid (on pool-141-149-209-23.syr.east.verizon.net)
Message-ID: <Xns92E3BCBB5A30Easu1cornelledu@132.236.56.8>
References: <Pine DOT GSO DOT 4 DOT 44L-027 DOT 0212131159570 DOT 4357-100000 AT unix4 DOT andrew DOT cmu DOT edu>
NNTP-Posting-Host: pool-141-149-209-23.syr.east.verizon.net
X-Trace: news01.cit.cornell.edu 1039822390 1251 141.149.209.23 (13 Dec 2002 23:33:10 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 13 Dec 2002 23:33:10 GMT
User-Agent: Xnews/5.04.25
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Arthur J. O'Dwyer" <ajo AT andrew DOT cmu DOT edu> wrote in news:Pine.GSO.4.44L-
027 DOT 0212131159570 DOT 4357-100000 AT unix4 DOT andrew DOT cmu DOT edu:

> 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

that ain't a hack.

<snip>

> 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.

here is what you can do:

disable filename globbing.

decide if your program has been passed the optional filename argument.

call glob with that argument as the pattern.

for documentation on glob, see

info libc alpha glob


-- 
A. Sinan Unur
asu1 AT c-o-r-n-e-l-l DOT edu
Remove dashes for address
Spam bait: mailto:uce AT ftc DOT gov

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019