Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: [command line arguments] more elegant solution ?? |
| Date | 2016-12-11 20:06 -0500 |
| Organization | The Pitcher Digital Freehold |
| Message-ID | <o2kt43$hj2$1@dont-email.me> (permalink) |
| References | (2 earlier) <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> |
On Sunday December 11 2016 19:55, in comp.lang.c, "BartC" <bc@freeuk.com>
wrote:
> 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:
>>
>>> On Sunday December 11 2016 18:43, in comp.lang.c, "BartC" <bc@freeuk.com>
>>> wrote:
>
>>>> If the 3rd parameter is *, and there happens to be one file in the
>>>> directory with a numeric name, such as 9177, that will then appear as a
>>>> valid argument. (You may have noticed a big thread in the python group
>>>> about this.)
>>>
>>> Bart, as has been explained elsewhere, in more detail and in more polite
>>> language, your statement above is at best misleading, and at worst untrue.
>>>
>>> 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
> ...
>
> (How did you fix it so that you don't have to type "./" which drives me
> up the wall?)
>
>
>> And to illustrate permenant disable of globbing:
>> 19:08 $ bash -o noglob
>> We start in a -o noglob shell.
>>
>> 19:08 $ ls | wc -l
>> 158
>>
>> 158 files and directories (now includes the previously compiled Args
>> program, but we will replace that with a fresh version)
>>
>> 19:08 $ 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;
>> }
>>
>> Same bog-simple program to list passed-in arguments
>>
>> 19:08 $ cc -o Args -mtune=native -Wall -std=c99 -pedantic Args.c
>>
>> Same successful compile to C99 standards
>>
>> 19:08 $ Args *
>> argc == 2
>> argv[0] -> "Args"
>> argv[1] -> "*"
>>
>> Passed in argument *, got argument *
>> This time, no need to temporarily disable globbing in the commandline.
>
>>
>> QED
>>
>>> I said "at best, misleading", because you neglect to mention that, in
>>> Unix, globbing (expansion of wildcard parameters into filenames) is
>>> something done by the shell, not by the C runtime and (usually) not by the
>>> C program. It can be enabled or disabled on demand.
>
> I said it was a Linux quirk.
It's not a quirk. It is a feature.
And it's not specific to Linux; it is mandated by the Single Unix Standard and
POSIX.
> And while it may be possible to disable it
> (you said you did it temporarily, but didn't see how,
You didn't look.
To save you from having to read the post again, you temporarily disable
globbing in a Unix shell by surrounding the argument with singlequotes.
'*' will not glob
> unless you mean
> what you called the 'permanent' disablement),
To permanently disable globbing at the shell, you run a shell with the noglob
option.
> 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'.
Bullshit.
Take a look again. ls worked fine in the noglob shell.
>>> Please don't mislead the newbies.
>
> I'm a newbie when it comes to Linux. I don't know how to turn off
> globbing except using 'bash -o noglob' like your example (and don't know
> how to turn it on again except by restarting the terminal),
You
exit
the shell
> but these
> are the sort of extra instructions you don't want to give with your program.
So what? Does every car carry a copy of the Motor Vehicle Department's rules
and regulations for the road? Does every lightbulb come with a copy of the
Electrical Code?
The operating environment isn't /your/ concern.
> The instructions are to run it using 'program arg1 arg2', not do X
> first, run it, then do Y. Especially for a very unlikely possibility.
>
> >> Bart, as has been explained elsewhere, in more detail and in more polite
> >> language, your statement above is at best misleading, and at worst
> untrue.
> >>
>
> Is it?
>
> At the moment, I /can/ actually run a program as:
>
> ../program test.netlist ???
And, so you get globbing.
Unless you don't want globbing, in that case you either run the program in a
noglob shell or you quote the argument
../program test.netlist '???'
> where 'program' sees argv[1] and argv[2] as "test.netlist 123" when
> there is a single file "123" in the directory. It's not a concern for a
> student exercise, but if those parameters were critical, I would have to
> take the possibility seriously.
>
> Your user may have neglected the need to turn off globbing. And in fact
> it is an unreasonable requirement.
Sorry, fourty years of Unix shell operations says that you are wrong.
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
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