getopts¶
getopts | getopt (BSD) | getopt (GNU) |
---|---|---|
builtin Bash | bin: /usr/bin/getopt |
bin: /opt/homebrew/opt/gnu-getopt/bin/getopt |
option courte (-h) | option longue (--help, -h) | |
- | gère les flags vides | |
OPTIN et OPTARG |
Syntaxe:¶
getopts optstring varname [arg ...]
optstring:¶
- si une lettre est suivi par : , l'option attend un argument
- si optstring commence par : , la variable shell OPTARG est définie sur le caractère d'option trouvé, mais aucune sortie n'est écrite sur l'erreur standard ; sinon, la variable shell OPTARG n'est pas définie et un message de diagnostic est écrit sur l'erreur standart
# optstring "hf"
$ ./soco-cli-gui.sh -k
./soco-cli-gui.sh : option non permise -- k
Invalid option: -.
# optstring ":hf"
$ ./soco-cli-gui.sh -k
Invalid option: -k.
Dernière mise à jour:
November 9, 2023