$OPTARG
–
Last Argument Value Processed by getopts
$OPTARG
contains the value of the last option argument processed by the getopts
builtin.
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 ist eine Bash IDE mit Unterstützung für $OPTARG – probieren Sie es aus!