|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Greetings
SUN OS 5.10 IF I dont give any arguements to optargs switch it will take the value I define if I pass an argument to switch, it should take that value: #!/bin/ksh .. ~/.profile while getopts adl Opt do case $Opt in a) [ -z "$Listener" ] && Listener="LISTENER" echo start_listener echo start_db ;; d|D) echo DB=$OPTARG; if [ -z "$OPTARG" ] then # ORACLE_SID="$ORACLE_SID"; # Take it from ENV .profile echo start_db else ORACLE_SID="$OPTARG"; echo start_db fi ;; l|L) echo "LSNR=$OPTARG"; if [ -z "$OPTARG" ] then Listener="LISTENER" ;echo start_listener else Listener="$OPTARG"; echo start_listener fi ;; *)exit;; esac done Regards & Thanks BN |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
When you want a value to be passed to an option, you must follow the
option by a colon ( . But the option MUST be folowed by the value.The option letter is case-sensitive. If you ask for option a, d and l, do not test for D not L. > > while getopts adl Opt to be replaced by while getopts ad:l: Opt If the value is missing you will get an error. Regards, Stephane |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
2007-05-17, 20:45(-07), BN:
> Greetings > > SUN OS 5.10 > > IF I dont give any arguements to optargs switch it will take the value > I define > if I pass an argument to switch, it should take that value: [...] You can't have options with optional arguments with getopts. If -a was to take optional arguments, in cmd -a -b Is "-b" another option or an argument to -a. At http://stchaz.free.fr/ you'll find an implementation of getopts that support optional arguments to options. In which case, you have to write it: cmd -aARG cmd -a-b cmd -a (and there's no way to pass an empty argument). or cmd --long=arg cmd --long -- Stéphane |
|
![]() |
| Outils de la discussion | |
|
|