caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Wildcard expansion/command line
@ 2002-05-14  7:50 Jens Olsson
  2002-05-14  8:24 ` Maxence Guesdon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jens Olsson @ 2002-05-14  7:50 UTC (permalink / raw)
  To: caml-list

Hello,

This is my second time at the list. Feel good to be back :) Hope all of you are well! 

I have a question right away. It might not (probably not) be a Ocaml related question but I'll give it a shot!

I write a program that is invoked from the command line. All well, but when I was starting to make my program deal with wildcards I realized that the ocaml program gets its command line arguments expanded (if wildcards are used). I have included an example at the bottom of my mail to clarify if it is unclear what I mean.

Now, is this done by the OS or the shell? How do I controll this behaviour? Of course I can enclose any arguments within "" and expand any wildcards manually - but I figured, if programs like 'ls' don't have to use quotes, why should I. 

So, how does it work? 

regards

Jens
   

Example: If a directory has two files m1.txt and m2.txt, and my ocaml program (here called myprog) is invoked with wildcards it would behave something like this:

Example call         Command line arg within my program
./myprog m*       -> Sys.argv.(1) = "m1.txt"
./myprog m?.txt   -> Sys.argv.(1) = "m1.txt"
./myprog "m*"     -> Sys.argv.(1) = "m*"

ie, wildcards are expanded before given to my program.
-- 

Powered by Outblaze
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Wildcard expansion/command line
  2002-05-14  7:50 [Caml-list] Wildcard expansion/command line Jens Olsson
@ 2002-05-14  8:24 ` Maxence Guesdon
  2002-05-14 12:52   ` T. Kurt Bond
  2002-05-14 13:30 ` Oliver Bandel
  2002-05-14 15:52 ` John Max Skaller
  2 siblings, 1 reply; 6+ messages in thread
From: Maxence Guesdon @ 2002-05-14  8:24 UTC (permalink / raw)
  To: Jens Olsson; +Cc: caml-list


> So, how does it work? 

*the shell* expands your unquoted wildcards before passing the args to your program.

> Example: If a directory has two files m1.txt and m2.txt, and my ocaml program (here called myprog) is invoked with wildcards it would behave something like this:
> 
> Example call         Command line arg within my program
> ./myprog m*       -> Sys.argv.(1) = "m1.txt"
> ./myprog m?.txt   -> Sys.argv.(1) = "m1.txt"
> ./myprog "m*"     -> Sys.argv.(1) = "m*"

You will have :
 ./myprog m*       -> Sys.argv.(1) = "m1.txt" and Sys.argv.(2) = "m2.txt"
 ./myprog m?.txt   -> Sys.argv.(1) = "m1.txt" and Sys.argv.(2) = "m2.txt"
 ./myprog "m*"     -> Sys.argv.(1) = "m*" since the * is inside quotes

Maxence Guesdon
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Wildcard expansion/command line
  2002-05-14  8:24 ` Maxence Guesdon
@ 2002-05-14 12:52   ` T. Kurt Bond
  2002-05-14 13:11     ` Dave Mason
  0 siblings, 1 reply; 6+ messages in thread
From: T. Kurt Bond @ 2002-05-14 12:52 UTC (permalink / raw)
  To: caml-list

Maxence Guesdon writes:
> 
> > So, how does it work? 
> 
> *the shell* expands your unquoted wildcards before passing the args
> to your program.

Not so, strictly speaking.  Under MS Windows the O'Caml runtime
apparently expands wildcards itself, if the shell hasn't already.  (See
byterun/main.c:main() for the call to expand_command_line() and look 
at win32.c for expand_command_line() and its helper functions.)

What did it do under pre-X versions of MacOS?

I think that historically having the shell expand the wildcards for
the program was the *unusual* situation and having the program expand
the wildcards itself was usual.  The "program expands wildcards" has
its advantages (as anybody who has used the VMS command "$ rename
*.COM *.SAV" can attest) but having the shell do it makes most
programs simpler, which is probably why Unix ended up with the shell
doing the work.
-- 
T. Kurt Bond, tkb@tkb.mpl.com

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Wildcard expansion/command line
  2002-05-14 12:52   ` T. Kurt Bond
@ 2002-05-14 13:11     ` Dave Mason
  0 siblings, 0 replies; 6+ messages in thread
From: Dave Mason @ 2002-05-14 13:11 UTC (permalink / raw)
  To: caml-list

>>>>> On Tue, 14 May 2002 08:52:32 -0400, "T. Kurt Bond" <tkb@tkb.mpl.com> said:

> having the shell do it makes most programs simpler, which is
> probably why Unix ended up with the shell doing the work.

And the other reason.... think 64Kb address spaces and 128Kb machines,
and no shared libraries.

Today the advantage for it is absolute consistency.

../Dave
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Wildcard expansion/command line
  2002-05-14  7:50 [Caml-list] Wildcard expansion/command line Jens Olsson
  2002-05-14  8:24 ` Maxence Guesdon
@ 2002-05-14 13:30 ` Oliver Bandel
  2002-05-14 15:52 ` John Max Skaller
  2 siblings, 0 replies; 6+ messages in thread
From: Oliver Bandel @ 2002-05-14 13:30 UTC (permalink / raw)
  To: Jens Olsson; +Cc: caml-list

Hello,

On Tue, 14 May 2002, Jens Olsson wrote:

> Hello,
> 
> This is my second time at the list. Feel good to be back :) Hope all of you are well! 
> 
> I have a question right away. It might not (probably not) be a Ocaml related question but I'll give it a shot!
> 
> I write a program that is invoked from the command line. All well, but when I was starting to make my program deal with wildcards I realized that the ocaml program gets its command line arguments expanded (if wildcards are used). I have included an exam
ple at the bottom of my mail to clarify if it is unclear what I mean.

[...]
> Example call         Command line arg within my program
> ./myprog m*       -> Sys.argv.(1) = "m1.txt"
> ./myprog m?.txt   -> Sys.argv.(1) = "m1.txt"
> ./myprog "m*"     -> Sys.argv.(1) = "m*"
> 
> ie, wildcards are expanded before given to my program.

This is typical bwehaviour of unix-shells, and that's what
they are good for. That's, why working with shells is so
easy. :)

If you don't want that behaviour, write your own shell, or
let your program explicitly read the arguments in.

Ciao,
   Oliver

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Wildcard expansion/command line
  2002-05-14  7:50 [Caml-list] Wildcard expansion/command line Jens Olsson
  2002-05-14  8:24 ` Maxence Guesdon
  2002-05-14 13:30 ` Oliver Bandel
@ 2002-05-14 15:52 ` John Max Skaller
  2 siblings, 0 replies; 6+ messages in thread
From: John Max Skaller @ 2002-05-14 15:52 UTC (permalink / raw)
  To: Jens Olsson; +Cc: caml-list

>
>
>Is this done by the OS or the shell?
>
The shell. Bash, for example, expands wildcards.
Not all shells do.

-- 
John Max Skaller, mailto:skaller@ozemail.com.au
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.
voice:61-2-9660-0850




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-05-14 15:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-14  7:50 [Caml-list] Wildcard expansion/command line Jens Olsson
2002-05-14  8:24 ` Maxence Guesdon
2002-05-14 12:52   ` T. Kurt Bond
2002-05-14 13:11     ` Dave Mason
2002-05-14 13:30 ` Oliver Bandel
2002-05-14 15:52 ` John Max Skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).