"Bash getopts 예제"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source lang='cli'> +<source lang='console'>))
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
3번째 줄: 3번째 줄:


==소스==
==소스==
<source lang='bash'>
<syntaxhighlight lang='bash'>
#!/bin/sh
#!/bin/sh
while getopts "c:i:" arg
while getopts "c:i:" arg
15번째 줄: 15번째 줄:
echo CONFIG_FILE = [$CONGIF_FILE]
echo CONFIG_FILE = [$CONGIF_FILE]
echo IP_ADDRESS = [$IP_ADDRESS]
echo IP_ADDRESS = [$IP_ADDRESS]
</source>
</syntaxhighlight>


==실행결과==
==실행결과==
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# sh test.sh -c hello.cfg -i 123.45.67.89
[root@zetawiki ~]# sh test.sh -c hello.cfg -i 123.45.67.89
CONFIG_FILE = [hello.cfg]
CONFIG_FILE = [hello.cfg]
IP_ADDRESS = [123.45.67.89]
IP_ADDRESS = [123.45.67.89]
</source>
</syntaxhighlight>
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# sh test.sh -i 123.45.67.89
[root@zetawiki ~]# sh test.sh -i 123.45.67.89
CONFIG_FILE = []
CONFIG_FILE = []
IP_ADDRESS = [123.45.67.89]
IP_ADDRESS = [123.45.67.89]
</source>
</syntaxhighlight>
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# sh test.sh
[root@zetawiki ~]# sh test.sh
CONFIG_FILE = []
CONFIG_FILE = []
IP_ADDRESS = []
IP_ADDRESS = []
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
39번째 줄: 39번째 줄:
*[[case]]
*[[case]]


==참고 자료==
==참고==
*http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds2/getopts.htm
*http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds2/getopts.htm


[[분류: bash]]
[[분류: bash]]

2020년 11월 2일 (월) 02:37 기준 최신판

bash getopts example
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@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 = []

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}