Bash getopts 예제

Jmnote (토론 | 기여)님의 2014년 4월 18일 (금) 14:29 판 (새 문서: ;Bash getopts 예제 ==소스== <source lang='bash'> #!/bin/sh while getopts "c:i:" arg do case $arg in c) CONGIF_FILE=$OPTARG ;; i) IP_ADDRESS=$OPTARG ;; esac done ...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
Bash getopts 예제

1 소스

#!/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]

2 실행결과

[root@jmnote ~]# sh test.sh -c hello.cfg -i 123.45.67.89
CONFIG_FILE = [hello.cfg]
IP_ADDRESS = [123.45.67.89]
[root@jmnote ~]# sh test.sh -i 123.45.67.89
CONFIG_FILE = []
IP_ADDRESS = [123.45.67.89]
[root@jmnote ~]# sh test.sh
CONFIG_FILE = []
IP_ADDRESS = []
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}