$OPTARG
–
Last Argument Value Processed by getopts
$OPTARG
contains the value of the last option argument processed by the getopts
command.
Links
Examples
- Print value passed to argument
-v
: 1 2 3 4 5 6 7 8 9 10 11 12 13
usage() { echo "$0 usage: -v <value>"; exit 0; } [ $# -eq 0 ] && usage declare value # : because -v requires a value while getopts "v:" arg; do case $arg in v) value="$OPTARG" ;; *) usage ;; esac done echo "Value passed to -v: $value"
BashSupport Pro 是一款支持 optarg** 的 **Zsh 集成开发环境 - 立即试用!