Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #30519

Re: Command line arguments

From Ken Brody <kenbrody@spamcop.net>
Newsgroups comp.lang.c
Subject Re: Command line arguments
Date 2013-01-22 15:32 -0500
Organization A noiseless patient Spider
Message-ID <kdmt05$ugf$2@dont-email.me> (permalink)
References (3 earlier) <_1HHs.63$kp4.24@newsfe09.iad> <XkHHs.1971$k04.70@fx20.fr7> <6AHHs.22803$fh5.11839@newsfe26.iad> <kcnhf2$6lm$1@dont-email.me> <kcod00$kt2$1@reader1.panix.com>

Show all headers | View raw


On 1/11/2013 1:54 AM, JohnF wrote:
> BruceS <bruces42@hotmail.com> wrote:
>> <<snip>>  From a terminal (in Linux), type 'echo *', and it
>> echos a list of the files in that directory.  Enclose in quotes (as
>> suggested elsethread), and type 'echo "*"', and get a single asterix.
>
> No longer a C question, per se, but bash's behavior (at least on
> my slackware 14.0 box) is a bit more complicated than suggested above.
> echo *     echoes a list of all files as stated
> echo t*.c  echoes test.c because that's the only such file in my /home
> echo a*.c  echoes a*.c   apparently because there are no a*.c files at all
> So if there are no matches, it reverts to echoing the string rather
> than emitting an error like ls would. Is there a more general rule
> behind that behavior? I ask because I also have a C program,
> in this case evaluating command-line expressions which can be,
> say, a*b, and I've never (so far) had any problem. Is that just
> lucky because there never happened to be any filename matches?

"ls" gives an error, because it gets passed the argument "a*.c", and there 
is no such file by that name.  Why should "echo" give an error when passed 
the argument "a*.c"?

The shell is being consistent -- if no file matches the wildcard, then that 
raw wildcard is passed.  What the program chooses to do with that argument 
is up to that program.

Back to comp.lang.c | Previous | Next | Find similar | Unroll thread


Thread

Re: Command line arguments Ken Brody <kenbrody@spamcop.net> - 2013-01-22 15:32 -0500

csiph-web