尽管用 getopts 可以支持选项化的参数,但是它有几个个缺点:不支持长选项 - help 或者 --help 这类的选项,对于其他非选项的终端参数则会忽略,而且 getopts 的选项要么带参数,要么不带参数。 如果需要使用长选项,可以考虑使用 getopt 这个内建命令。 ARGS=`getopt -o ab:c:: -al along,blong:,clong:: -n ...
./test.sh -abc :短选项,和上一种方法的效果一样,只是将所有的选项写在一起。 ./test.sh -a args -b -c :短选项,其中-a需要参数,而-b -c不需参数。 ./test.sh --a-long=args --b-long :长选项 getopt参数说明# TEMP=getopt -o ab:c:: --long a-long,b-long:,c-long:: -n 'exampl...
ARGS=`getopt -o a:m:h --long arch:,module:,help,asan: -n 'build.sh' -- "$@"` if [ $? != 0 ]; then echo "Terminating..." exit 1 fi #将规范化后的命令行参数分配至位置参数($1,$2,...) eval set -- "${ARGS}" while true do case "$1" in -h|--help...
getopts和getopt功能相似但又不完全相同,其中getopt是独立的可执行文件,而getopts是由Bash内置的。 先来看看参数传递的典型用法: * ./test.sh -a -b -c : 短选项,各选项不需参数 * ./test.sh -abc : 短选项,和上一种方法的效果一样,只是将所有的选项写在一起。 * ./test.sh -a args -b -c :短...
RUNNING_SHELL=$(ps -p $$ -o args= | sed 's|^-||') case "$RUNNING_SHELL" in */*) ;; default) RUNNING_SHELL=$(which "$RUNNING_SHELL") ;; esac fi fi fi # Some final fallback locations if [ -z "$RUNNING_SHELL" ] || [ ! -f "$RUNNING_SHELL" ]; then ...
ARGS=$(getopt -o c,u: --long coverage,user:,test_list: -- "$@") if [ $? != 0 ]; then echo "Terminating..." exit 1 fi eval set -- "${ARGS}" declare -g LCOV_ENABLE=FALSE declare -g RUN_TEST_USER="cantiandba" declare -g TEST_LIST="enableCases_gcov...
args=$(getopt -o a:r:c:lhs -l add:,rm:,clean\!,list,ls:,path:,help,show -- $*)# check if no arguments were given, and that version is not set if [[ ($? -ne 0 || $#* -eq 0) && -z $wd_print_version ]] then ...
_cmdline_args=$(getopt -o $_short_args_joined --long $_long_args_joined -n $PROG_NAME -- "$@" || usage -1) eval set -- "$_cmdline_args" if [ $# != 0 ]; then while true; do case "$1" in -c | --coverage) shift export MLUOP_BUILD_COVERAGE_TEST="ON" ...
ARGS=$(getopt -o "hp:n:c:r:wsudx" -l "help,project:,net:,count:,release:,wipe,sentinel,update,debug,startnodes" -n "install.sh" -- "$@");#Bad arguments if [ $? -ne 0 ]; then help; fieval set -- "$ARGS";while true; do ...
GALA_DEPLOY_MODE="docker" KAFKA_ADDR="localhost" ARGS=`getopt -a -o K:p:S: --long kafka:,pyroscope:,k8s,srcdir: -- "$@"` [ $? -ne 0 ] && (print_usage; exit 1) eval set -- "${ARGS}" while true do case $1 in -K|--kafka) KAFKA_ADDR=$2 shift;; ...