2013. 11. 19. 14:34
Step 1. add option word:
Step 2. add option case
#!/bin/bash
echo "OPTIND starts at $OPTIND"
while getopts ":p:q:d:" optname
do
case "$optname" in
"p")
echo "Option $optname is specified"
;;
"q")
echo "Option $optname has value $OPTARG"
;;
"d")
echo "Directory is $OPTARG"
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
echo "OPTIND is now $OPTIND"
done
reference : http://www.ibm.com/developerworks/opensource/library/l-bash-parameters/index.html
'Programming > Bash shell' 카테고리의 다른 글
check wheter mySQL is running in bash shell (0) | 2013.11.20 |
---|---|
check if mysql database exists in bash shell (0) | 2013.11.20 |
Using shell script to control in mySQL (0) | 2013.11.19 |
Replace string in bash shell (0) | 2013.11.18 |
Bash shell script to swap two number (0) | 2013.11.12 |