"Bash 스크립트 인수 있는지 검사"의 두 판 사이의 차이

잔글 (로봇: 자동으로 텍스트 교체 (-[root@jmnote +[root@zetawiki))
2번째 줄: 2번째 줄:
;Bash 스크립트 인수 있는지 확인
;Bash 스크립트 인수 있는지 확인


==테스트 소스==
==예시 1==
<source lang='bash'>
<source lang='bash'>
#!/bin/bash
#!/bin/bash
12번째 줄: 12번째 줄:
</source>
</source>


==실행 결과==
;실행예시
<source lang='cli'>
<source lang='cli'>
[root@zetawiki ~]# sh test.sh  
[root@zetawiki ~]# sh test.sh  
24번째 줄: 24번째 줄:
[root@zetawiki ~]# sh test.sh 1 2
[root@zetawiki ~]# sh test.sh 1 2
OK
OK
</source>
==예시 2==
<source lang='bash'>
#!/bin/bash
if [ $# -ne 1 ] ; then
    echo "Usage: greet.sh John"
    exit 0
fi
echo "Hello, $1."
</source>
*실행예시
<source lang='cli'>
root@zetawiki:~# sh greet.sh
Usage: greet.sh John
root@zetawiki:~# sh greet.sh John
Hello, John.
root@zetawiki:~# sh greet.sh John Smith
Usage: greet.sh John
root@zetawiki:~# sh greet.sh "John Smith"
Hello, John Smith.
</source>
</source>



2016년 1월 5일 (화) 15:14 판

Bash no arguments warning
Bash 스크립트 인수 있는지 확인

1 예시 1

#!/bin/bash
if [ $# -eq 0 ] ; then
    echo "Warning: no arguments"
    exit 0
fi
echo "OK"
실행예시
[root@zetawiki ~]# sh test.sh 
Warning: no arguments
[root@zetawiki ~]# sh test.sh asdf
OK
[root@zetawiki ~]# sh test.sh 1
OK
[root@zetawiki ~]# sh test.sh 1 2
OK

2 예시 2

#!/bin/bash
if [ $# -ne 1 ] ; then
    echo "Usage: greet.sh John"
    exit 0
fi
echo "Hello, $1."
  • 실행예시
root@zetawiki:~# sh greet.sh 
Usage: greet.sh John
root@zetawiki:~# sh greet.sh John
Hello, John.
root@zetawiki:~# sh greet.sh John Smith
Usage: greet.sh John
root@zetawiki:~# sh greet.sh "John Smith"
Hello, John Smith.

3 같이 보기

4 참고 자료

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