Your commit message
This commit is contained in:
27
基础脚本/参数传递.sh
Normal file
27
基础脚本/参数传递.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 输出参数索引
|
||||
echo "OPTIND starts at $OPTIND"
|
||||
# 接收参数
|
||||
while getopts ":pq:" optname
|
||||
do
|
||||
case "$optname" in
|
||||
"p")
|
||||
echo "Option $optname is specified"
|
||||
;;
|
||||
"q")
|
||||
echo "Option $optname has value $OPTARG"
|
||||
;;
|
||||
"?")
|
||||
echo "Unknown option $OPTARG"
|
||||
;;
|
||||
":")
|
||||
echo "No argument value for option $OPTARG"
|
||||
;;
|
||||
*)
|
||||
# Should not occur
|
||||
echo "Unknown error while processing options"
|
||||
;;
|
||||
esac
|
||||
echo "OPtIND now is $OPTIND"
|
||||
done
|
||||
Reference in New Issue
Block a user