2019-05-10 11:17:57 +08:00
|
|
|
#!/bin/bash
|
2019-10-10 08:56:31 +08:00
|
|
|
|
2019-05-10 11:17:57 +08:00
|
|
|
# processing options and parameters with getopts
|
|
|
|
|
|
|
|
while getopts :ab:cd opt
|
|
|
|
do
|
2019-10-10 08:56:31 +08:00
|
|
|
case "$opt" in
|
|
|
|
a) echo "Found the -a option" ;;
|
|
|
|
b) echo "Found the -b option,with value $OPTARG" ;;
|
|
|
|
c) echo "Found the -c option" ;;
|
|
|
|
d) echo "Found the -d option" ;;
|
|
|
|
*) echo "Unknown option: $opt" ;;
|
|
|
|
esac
|
2019-05-10 11:17:57 +08:00
|
|
|
done
|
|
|
|
shift $[ $OPTIND - 1 ]
|
|
|
|
count=1
|
|
|
|
for param in "$@"
|
|
|
|
do
|
2019-10-10 08:56:31 +08:00
|
|
|
echo "Parameter $count: $param"
|
|
|
|
count=$[ $count + 1 ]
|
2019-05-10 11:17:57 +08:00
|
|
|
done
|