getopt

来自百合仙子's Wiki
跳转到导航 跳转到搜索

命令行使用示例

#!/bin/zsh -e

progname=$0
OPTS=$(getopt -o vhw --long virtualbox,help,real -n $progname -- "$@")
eval set -- "$OPTS"

opt_vbox=0
ifdry=-n

usage () {
  echo "usage: $progname [-w|--real] [-v|--virtualbox] DEST_DIR"
}

while true; do
  case $1 in
    -v|--virtualbox) do_vbox=1; shift;;
    -w|--real) ifdry=; shift;;
    -h|--help) usage; exit; shift;;
    --) shift; break;;
    *) break;;
  esac
done

dest=$1

# ...

参见