- bash getopts example
- Bash getopts 예제
소스
#!/bin/sh
while getopts "c:i:" arg
do
case $arg in
c) CONGIF_FILE=$OPTARG ;;
i) IP_ADDRESS=$OPTARG ;;
esac
done
echo CONFIG_FILE = [$CONGIF_FILE]
echo IP_ADDRESS = [$IP_ADDRESS]
실행결과
[root@zetawiki ~]# sh test.sh -c hello.cfg -i 123.45.67.89
CONFIG_FILE = [hello.cfg]
IP_ADDRESS = [123.45.67.89]
[root@zetawiki ~]# sh test.sh -i 123.45.67.89
CONFIG_FILE = []
IP_ADDRESS = [123.45.67.89]
[root@zetawiki ~]# sh test.sh
CONFIG_FILE = []
IP_ADDRESS = []