Re: Writing a unix command prompt

On 2006-01-29, Barry Margolin wrote:
> In article <1O3Df.215188$D47.8103@xxxxxxxxxxxxxxxxxxxxxxxxx>,
> Robert Harris <robert.f.harris@xxxxxxxxxxxxxxxx> wrote:
>> repairman2003@xxxxxxxxx wrote:
>> > I'm writing a command prompt for unix and I've run into some problems:
>> >
>> > [snip]
>> >
>> > The problems
>> > 1. The workaround listed above.
>> > 2. One argument commands work fine but multiple doesn't. Eg. ls -a
>> > works fine, ls -al works fine but ls -a -l doesn't work. Any
>> > subsequent commands that don't have arguments don't work either, eg.
>> > ls works, then ls -a works, but ls again doesn't work.
>> >
>> > Any help is greatly appriciated!
>> use getopt(3) to parse your command line.
> getopt() is something that can be used in the program that gets
> executed, it has nothing to do with parsing by the shell itself.

You can feed any array to getopt. The command line just has to be
parsed into an array first.

Chris F.A. Johnson, author | <>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence

Relevant Pages

  • A plan for handling command line options
    ... Getopt is meant to be used by calling it once for each command ... In each case the first argument is an option string and the ... provide an error handling interface that the user can access. ...
  • Re: Start em early: font rage
    ... introducing a command option is a dash. ... The getopt subroutine returns the next flag letter specified on ... getopt recognizes two hyphens to delimit the end of the ...
  • Re: A plan for handling command line options
    ... In the C programming world there is a common utility called getopt that is used for processing command line arguments. ... In each case the first argument is an option string and the second is the address of the place where a value will be placed. ... One approach to error handling is to set errno and abort - this is plausible since the program is still being initialized. ...
  • RE: Solaris telnet vulnberability - how many on your network?
    ... I have now set up a virtual Solaris 8 box to test this with root access, and it appears you are correct. ... When run as root, "login -f root" presents a login prompt, just like login without arguments. ... For instance, it is sometimes convenient to replace another command by a symlink to /bin/true in order to test the effect of the command succeeding, in which case /bin/true might receive arbitrary command line arguments. ... My point is just that it's peculiar that -f should have been implemented so far as adding it to the getopt list and giving it some sort of effect without implementing the "right" semantics or documenting it. ...
  • Re: Command-line parameter parsing
    ... As it chances I am doing a command line processor so the issue is live ... Posix getopt uses the first; it is suitable for very simple grammars. ...