💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] ## 参数的典型用法 先来看看参数传递的典型用法: ``` ./test.sh -a -b -c : 短选项,各选项不需参数 ./test.sh -abc : 短选项,和上一种方法的效果一样,只是将所有的选项写在一起。 ./test.sh -a args -b -c :短选项,其中-a需要参数,而-b -c不需参数。 ./test.sh --a-long=args --b-long :长选项 ``` ## getopts - 不支持长选项 ## 实例 <details> <summary>test.sh</summary> ``` #!/bin/bash while getopts "a:bc" arg #选项后面的冒号表示该选项需要参数 do case $arg in a) echo "a's arg:$OPTARG" #参数存在$OPTARG中 ;; b) echo "b" ;; c) echo "c" ;; ?) #当有不认识的选项的时候arg为? echo "unkonw argument" exit 1 ;; esac done ``` </details> <br/> ``` > ./test.sh -a arg1 -b -c // or ./test.sh -a arg1 -bc a's arg:arg 1 b c ```