getopts
Parse shell options from arguments. Note: This command does not support longform options and thus using
getoptis recommended instead. More information: https://www.gnu.org/software/bash/manual/bash.html#index-getopts.
- Check if an option is the first set option in the current context:
getopts ; echo $
- Check if an option is set in a string (specified option must be the first element of the string):
getopts ""; echo $
- Set an option to require an argument and print them:
getopts : ; echo $ $OPTARG
- Check for multiple options:
while getopts ; do case $ in x) ;; y) ;; z) ;; esac; done
- Set
getoptsto silent mode and handle option errors:
while getopts : ; do case $ in x) ;; :) ;; ?) esac;; done
- Reset
getopts:
OPTIND=1
来源:tldr-pages contributors · 作者与贡献记录 · CC BY 4.0。离线整理了版式、链接和媒体显示。
