PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Is it possible in optargs
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Is it possible in optargs

Réponse
 
LinkBack Outils de la discussion
Vieux 18/05/2007, 04h45   #1
BN
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Is it possible in optargs

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

  Réponse avec citation
Vieux 18/05/2007, 09h32   #2
sg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is it possible in optargs

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
  Réponse avec citation
Vieux 19/05/2007, 18h41   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is it possible in optargs

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h20.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09417 seconds with 11 queries