linux-tutorial/codes/shell/输入和输出/处理带值的选项.sh
2019-10-29 18:22:19 +08:00

26 lines
429 B
Bash

#!/usr/bin/env bash
# extracting command line options and values
while [ -n "$1" ]
do
case "$1" in
-a) echo "Found the -a option" ;;
-b) param="$2"
echo "Found the -b option, with parameter value $param"
shift ;;
-c) echo "Found the -c option" ;;
--) shift
break ;;
*) echo "$1 is not an option" ;;
esac
shift
done
count=1
for param in "$@"
do
echo "Parameter #$count : $param"
count=$[ $count + 1 ]
done