Mail Archives: djgpp/2002/12/13/18:45:41
"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 -