1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > shell 命令行选项处理方法 getopts

shell 命令行选项处理方法 getopts

时间:2023-08-20 12:02:05

相关推荐

shell 命令行选项处理方法 getopts

一个完善的shell脚本应该能处理行如 -option 的命令行选项,bash 有一个内置的命令 getopts 可用来处理命令行选项 示例,用法 getopts.h -x -y YARG -z ZARG * bbkf:/yzyfb/report/cdq/bash$cat getopts.sh

#!/bin/bash

# getopts.sh - Using getopts

############################## while getopts xy:z: opt;

do

case $opt in

x) xopt=-x set;;

y) yopt="-y set and called with $OPTARG" ;;

z) zopt="-z set and called with $OPTARG" ;;

\?) echo USAGE: getopts.sh [-x] [-y arg] [-z arg] file ...

exit 1

esac

done shift $(($OPTIND - 1 )) echo ${xopt:-did not use -x}

echo ${yopt:-did not use -y}

echo ${zopt:-did not use -z}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。