本文主要是介绍shell系列------循环解析脚本的参数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
记录一下monkey的参数解析流程
useage() {
echo "useage : monkey_test [--case # <test case #>]"
echo " [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]"
echo " [-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]"
echo " [-t <seconds>]"
echo " [--seed # <seed #>]"
echo " [--package-list <test case package list>]"
echo " [--phonenumber # <fixed dial #>]"
echo " [--IMETest]"
echo " [--version]"
echo " [-h]"
exit 0
}
#parsing the argument
while [ $# != 0 ]; do #参数个数不等于0
flag="$1"
case "$flag" in
-h) useage;
;;
-t) if [ $# -gt 1 ]; then #add the package argument #参数个数大于1
arg3="$2"
#Set the CountDwon timer
countdowntimer="$arg3"
shift
else
echo "UnKnown: argument : $flag"
useage;
fi
;;
-p) if [ $# -gt 1 ]; then #add the package argument and install the empty Activity apk
arg3="$2"
package="$package -p $arg3" #
ispackage="true"
shift #传入的参数左移一个,$2变成了$1
else
echo "UnKnown: argument : $flag"
useage;
fi
;;
-c) if [ $# -gt 1 ]; then #add the category argument
arg="$2"
category="$category -c $arg"
shift
else
echo "UnKnown: argument : $flag"
useage;
fi
;;
--seed) if [ $# -gt 1 ]; then
arg1="$2"
seed=$arg1
shift
else
echo "UnKnown: argument : $flag"
useage;
fi
;;
--case) if [ $# -gt 1 ]; then
pm install /system/scripts/monkey/EmptyActivity.obj
arg2="$2"
echo "Choose Test Case : $arg2"
test_case_package=`cat $package_list | head -n $arg2 | tail -n 1 | awk '{print $2}'| tr -d '\r\n'`
#ToDo: modify to get more argument
#test_case_category=`cat $package_list | head -n $arg2 | tail -n 1 | awk '{print NF}'`
package=" -p $test_case_package"
echo "package : $package"
echo "category : $category"
run=259200
shift
else
echo "UnKnown: argument : $flag"
useage;
fi
;;
--package-list) awk '{print $1 " " $3}' $package_list
exit 0
;;
--version) echo "monkey script version $version"
exit 0
;;
--phonenumber) if [ $# -gt 1 ]; then
arg3="$2"
phonenumber="$arg3"
shift
else
echo "UnKnown: argument : $flag"
useage;
fi
;;
--IMETest)
pm install /system/scripts/monkey/TestIME.obj
package="$package -p com.android.testime"
;;
--w)
argument="--pkg-whitelist-file $2"
shift
;;
--bl)
argument="--pkg-blacklist-file $2"
shift
;;
*) echo "UnKnown: argument : $flag"
useage;
;;
esac
shift
done
这篇关于shell系列------循环解析脚本的参数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!