Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!sdd.hp.com!cs.utexas.edu!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.fortran Subject: Re: Command line arguements? Message-ID: <6054@goanna.cs.rmit.oz.au> Date: 31 May 91 08:22:19 GMT References: <24632@lanl.gov> <24713@lanl.gov> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 65 In article <24713@lanl.gov>, jlg@cochiti.lanl.gov (Jim Giles) writes: > As I said above, the _shell_ processes the command line before I get to > look at it. So, getarg() and iargc() don't give me the arguments that > the user typed, they give me the _processed_ arguments. This means that > my command line syntax has to avoid quotes, backslashes, wildcard characters, > and probably a few other things. Yes and no. It is not the case that every program is invoked from ``the'' shell (do you mean sh, csh, tcsh, ksh, bash, rc, tcl, or what?). It may be that there never *was* any such thing as a line typed by ``the user''. Your command line syntax, if it uses any of the usual meta-characters {}[]()<>,;$\'", will need quoting, but the only character which is actually forbidden to you is NUL. > If the shell passed the _unprocessed_ command line _in_addition_ to the > parsed argument list (either as another argument to main() or as an > environment variable) then I could design code which used any command > line syntax I wanted. Improved Giles-specific shell: while read line ; do export COMMAND_LINE COMMAND_LINES="$line" eval "$line" done > In particular, I could apply the same wildcard > and quoting conventions to alternative search spaces - not just to local > file names. Not quite. You would have to program them yourself. UNIX shell wild-cards are specialised to file names (for example, none of them will match a '/'). If the things you want to match against aren't file names (as in your phone book example), that may not be appropriate. My equivalent of 'phone' expands to a call to Awk, and the pattern matching provided by Awk is not identical to shell file name wildcards. > For example, I could have a phonebook program that listed > phone numbers for people specified as: > > cochiti => phone s*m S*de > > Which would find (say) Sam Spade and print his number. It would also > find Slim Shade, etc.. You get the picture. At present, the only ways > to do this are to require the user to quote the patterns to get them > past the shell or to make the utility interactive: ignore the command > line and ask for the name interactively. Well, you _could_ do phone <<'.' s*m S*de . I've used TOPS-10 (where you _only_ get an uninterpreted command line) and VM/CMS (where you can get both a tokenised and an uninterpreted command line), and for that reason I very much like the approach taken by the UNIX shells. This divergence in the interfaces offered by various operating systems is of course why "get command line arguments" is not a standard feature of Fortran. -- Should you ever intend to dull the wits of a young man and to incapacitate his brains for any kind of thought whatever, then you cannot do better than give him Hegel to read. -- Schopenhauer.