mirror of
https://github.com/dunwu/linux-tutorial.git
synced 2024-04-15 19:55:24 +08:00
22 lines
434 B
Bash
22 lines
434 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
# processing options and parameters with getopts
|
||
|
|
||
|
while getopts :ab:cd opt
|
||
|
do
|
||
|
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
|
||
|
done
|
||
|
shift $[ $OPTIND - 1 ]
|
||
|
count=1
|
||
|
for param in "$@"
|
||
|
do
|
||
|
echo "Parameter $count: $param"
|
||
|
count=$[ $count + 1 ]
|
||
|
done
|