Discussion in 'Programming/Scripts' started by alexus, Mar 2, 2007.

  1. alexus

    alexus New Member


    i'm writing shell script and i'm at the point where i need getopts help
    how can i use getopts and have multiple arguments (some of them is required and some of them is optional)? for instance.

    i need to run shell with following arguments:

    --host/ip [host/ip]
    --file-list [file-list]

    here i also need to run either of those, not together... but one parameter is required, and if someone just run it with --sleep that wouldn't be sufficient since --host/ip or --file-list wasn't specified..

    --sleep [time]
    --status [print out status]

    from what I've Google'ed, all examples only shows you how to take 1 parameter and work with it, but i didn't find any where it would show you how to take more then one and in one case make something required

    sounds complicated i know :)
  2. falko

    falko Super Moderator ISPConfig Developer

    You can reference parameters in a script with $1, $2, $3, ...

    For example, if you run a script like this:
    ./ paramter1 parameter2
    then $1 contains parameter1, and $2 parameter2.
  3. insistkool

    insistkool New Member

Share This Page