背景:要写一个脚本每天统计昨天的数据
执行脚本可以传入时间
那么可以用while getopts 来循环获取参数
众所周知执行脚本时是可以给参数的
例如执行脚本sh test.sh -d 20211109
意思是执行test.sh脚本 给了参数 -d 值是20211109
那么
while getopts “r:” opt; do
echo “this is $opt, $OPTARG”
case $opt in
d)
runDt=date -d $OPTARG +%Y%m%d
;;
esac
done
这个时候 d)匹配上了 runDt就等于你执行脚本时的参数20211109了
while getopts作用
最新推荐文章于 2023-03-26 09:11:45 发布