Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: [command line arguments] more elegant solution ?? |
| Date | Sun, 11 Dec 2016 18:59:32 -0800 |
| Organization | None to speak of |
| Lines | 100 |
| Message-ID | <lnlgvlsvhn.fsf@kst-u.example.com> (permalink) |
| References | <f5132d7e-048b-4115-ad9e-4f5cfa8533e7@googlegroups.com> <o2k5rm$t8h$1@dont-email.me> <871sxew6n8.fsf@bsb.me.uk> <o2ko86$jgi$1@dont-email.me> <o2kpc1$rbg$1@dont-email.me> <o2kq0g$34c$1@dont-email.me> <o2ksfc$fvo$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx02.eternal-september.org; posting-host="5ae493c5c0eddd0692ad00c7942bf15f"; logging-data="27278"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qAzHB2u0yLB621xFKIbwn" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:yBM/ghjrQE86JOIXtTmp3KyTM5k= sha1:w86GZqcVs9BFY+dHa89evyrWFo8= |
| Xref | csiph.com comp.lang.c:98972 |
Show key headers only | View raw
BartC <bc@freeuk.com> writes:
> On 12/12/2016 00:13, Lew Pitcher wrote:
>> On Sunday December 11 2016 19:02, in comp.lang.c, "Lew Pitcher"
>> <lew.pitcher@digitalfreehold.ca> wrote:
[...]
>>> Witness:
> 18:55 $ ls | wc -l
>>> 157
>>>
>>> That's 157 files and directories in the current directory, including the
>>> source code Args.c
>>>
>>> 18:55 $ cat Args.c
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>>
>>> int main(int argc, char *argv[])
>>> {
>>> int argnum;
>>>
>>> printf("argc == %d\n",argc);
>>> for (argnum = 0; argnum < argc; ++argnum)
>>> printf("argv[%d] -> \"%s\"\n",argnum,argv[argnum]);
>>>
>>> return EXIT_SUCCESS;
>>> }
>>>
>>>
>>> Simple program, wot? Just prints argc, and each given argument
>>>
>>> 18:55 $ cc -o Args -mtune=native -Wall -std=c99 -pedantic Args.c
>>>
>>> Compiles clean to C99 standards
>>>
>>> 18:55 $ Args '*'
>>> argc == 2
>>> argv[0] -> "Args"
>>> argv[1] -> "*"
>>>
>>> Oops.... Passed * as argument, got * as argument.
>>
> I tried your program, and I got 125 arguments:
>
> ...$ gcc c.c -oc
> ...$ ./c
> argc == 125
> ...
If you had run the program exactly as you show it, you would have gotten
no arguments (argc==1). I'll bet you actually ran
./c *
The * is expanded by the shell to a list of file names; there's
nothing the program can do about it. That's just something you
have to be aware of. (I won't argue about whether the behavior is
a good idea.)
> (How did you fix it so that you don't have to type "./" which drives me
> up the wall?)
You can do that by adding the current directory, ".", to $PATH -- but I
strongly suggest *not* doing that. If you must, be sure to add it to
the end of $PATH, not the beginning. Otherwise you run the risk of
running arbitrary commands that happen to be in the current directory.
(Imagine you're in a directory containing a script called "ls" that does
something nasty.)
I'm sorry that typing "./" drives you up the wall; my honest advice is
to get used to it.
[...]
> I said it was a Linux quirk. And while it may be possible to disable it
> (you said you did it temporarily, but didn't see how, unless you mean
> what you called the 'permanent' disablement), I don't see that as an
> answer. If you disable it, then a whole load of other things that depend
> on it will stop working, such as 'ls'.
I hadn't even realized you could disable globbing; I probably knew about
it at some po, but I've never wanted to use it.
My own approach, and the one I recommend, is simply to be aware that *
expands to a list of file names, and to quote it if I want a literal *
character. And of course to be aware of the other expansion rules.
If you insist on disabling and reenabling globbing, if you're using bash
you can do it with these commands:
set -o noglob # disable globbing
set +o noglob # re-enable globbing
Again, I don't recommmend this (and I won't argue about the ugly
syntax).
[...]
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 07:56 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 16:47 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 09:16 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 09:26 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 19:05 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 11:15 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 11:53 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 20:03 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 12:26 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 12:33 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 20:33 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 12:35 -0800
Re: [command line arguments] more elegant solution ?? "James R. Kuyper" <jameskuyper@verizon.net> - 2016-12-11 16:06 -0500
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 13:11 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 13:20 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 13:25 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 21:32 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 13:44 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 13:47 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 21:56 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 14:04 -0800
Re: [command line arguments] more elegant solution ?? Robert Spanjaard <spamtrap@arumes.com> - 2016-12-11 23:07 +0100
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 14:15 -0800
Re: [command line arguments] more elegant solution ?? Robert Spanjaard <spamtrap@arumes.com> - 2016-12-11 23:32 +0100
Re: [command line arguments] more elegant solution ?? jameskuyper@verizon.net - 2016-12-11 14:42 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 14:52 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 14:40 -0800
Re: [command line arguments] more elegant solution ?? jameskuyper@verizon.net - 2016-12-11 14:55 -0800
Re: [command line arguments] more elegant solution ?? "James R. Kuyper" <jameskuyper@verizon.net> - 2016-12-11 19:44 -0500
Re: [command line arguments] more elegant solution ?? Richard Heathfield <rjh@cpax.org.uk> - 2016-12-11 23:20 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 15:28 -0800
Re: [command line arguments] more elegant solution ?? jameskuyper@verizon.net - 2016-12-11 16:28 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 18:57 +0000
Re: [command line arguments] more elegant solution ?? Barry Schwarz <schwarzb@dqel.com> - 2016-12-11 10:04 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 11:25 -0800
Re: [command line arguments] more elegant solution ?? BartC <bc@freeuk.com> - 2016-12-11 18:29 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 11:25 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-11 20:30 +0000
Re: [command line arguments] more elegant solution ?? BartC <bc@freeuk.com> - 2016-12-11 23:43 +0000
Re: [command line arguments] more elegant solution ?? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-11 19:02 -0500
Re: [command line arguments] more elegant solution ?? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-11 19:13 -0500
Re: [command line arguments] more elegant solution ?? BartC <bc@freeuk.com> - 2016-12-12 00:55 +0000
Re: [command line arguments] more elegant solution ?? BartC <bc@freeuk.com> - 2016-12-12 01:02 +0000
Re: [command line arguments] more elegant solution ?? Keith Thompson <kst-u@mib.org> - 2016-12-11 19:02 -0800
Re: [command line arguments] more elegant solution ?? BartC <bc@freeuk.com> - 2016-12-12 11:50 +0000
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-12 13:46 +0000
Re: [command line arguments] more elegant solution ?? BartC <bc@freeuk.com> - 2016-12-12 14:43 +0000
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-12 22:09 +0000
Re: [command line arguments] more elegant solution ?? Keith Thompson <kst-u@mib.org> - 2016-12-12 08:58 -0800
Re: [command line arguments] more elegant solution ?? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-11 20:06 -0500
Re: [command line arguments] more elegant solution ?? jameskuyper@verizon.net - 2016-12-11 17:37 -0800
Re: [command line arguments] more elegant solution ?? Keith Thompson <kst-u@mib.org> - 2016-12-11 18:59 -0800
Re: [command line arguments] more elegant solution ?? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-12 02:47 +0000
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-11 15:11 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-12 00:25 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-12 00:27 -0800
Re: [command line arguments] more elegant solution ?? Barry Schwarz <schwarzb@dqel.com> - 2016-12-12 01:01 -0800
Re: [command line arguments] more elegant solution ?? Dexterr <dejangru@gmail.com> - 2016-12-12 09:42 -0800
Re: [command line arguments] more elegant solution ?? "James R. Kuyper" <jameskuyper@verizon.net> - 2016-12-12 13:58 -0500
Re: [command line arguments] more elegant solution ?? Barry Schwarz <schwarzb@dqel.com> - 2016-12-12 14:18 -0800
csiph-web