一般我们通过下面的方式调用disk-partitioning.sh的时候,可以通过-d/-l等制定参数
./disk-partitioning.sh -d "${DEVICE}" -l "${DISKLABEL}" -f "${FILESYSTEM}" -s "${SKIP_INSTALL}"
对这样参数的解析可以参考下面这段。
while getopts "d:l:f:r:s:" o; do
case "$o" in
# The existing disk label on the device will be destroyed,
# and all data on this disk will be lost.
d) DEVICE="${OPTARG}" ;;
l) DISKLABEL="${OPTARG}" ;;
f) FILESYSTEM="${OPTARG}" ;;
s) SKIP_INSTALL="${OPTARG}" ;;
*) usage ;;
esac
done
当然也可以采用下面这种方式解析传递过来的参数,直接通过$1来得到位置参数,
- if [ "$TEST" = "stress_ng" ]; then
- ./aosp-24h-stress-test.sh -t $TEST -d $DURATION
- elif [ "$TEST" = "stress_oom" ]; then
- ./aosp-24h-stress-test.sh -t $TEST -d $DURATION
- elif [ "$TEST" = "stress_network" ]; then
- ./aosp-24h-stress-test.sh -t $TEST -d $DURATION -i $INTERFACE -l $LINK -m $MD5
- fi
while [ $# -gt 0 ]
do
case $1 in
-t|--test)
tests="$2"
;;
-d|--duration)
duration="$2"
;;
-i|--interface)
interface="$2"
;;
-l|--link)
link="$2"
;;
-m|--md5)
md5=$2
;;
-h|--help)
usage
exit 1
;;
*)
echo "Unknown option $@"
usage
exit 1
;;
esac
shift 2
done