Bash 숫자 비교

Bash 비교문
Bash 숫자 비교

1 같다[편집]

if [ $A = $B ]; then echo YES; else echo NO; fi
if [ $A -eq $B ]; then echo YES; else echo NO; fi
[root@zetawiki ~]# A=2; B=2; if [ $A = $B ]; then echo YES; else echo NO; fi
YES
[root@zetawiki ~]# A=2; B=3; if [ $A = $B ]; then echo YES; else echo NO; fi
NO

2 같지 않다[편집]

if [ $A -ne $B ]; then echo YES; else echo NO; fi
[root@zetawiki ~]# A=2; B=2; if [ $A -ne $B ]; then echo YES; else echo NO; fi
NO
[root@zetawiki ~]# A=2; B=3; if [ $A -ne $B ]; then echo YES; else echo NO; fi
YES

3 작다[편집]

if [ $A -lt $B ]; then echo YES; else echo NO; fi
[root@zetawiki ~]# A=2; B=1; if [ $A -lt $B ]; then echo YES; else echo NO; fi
NO
[root@zetawiki ~]# A=2; B=2; if [ $A -lt $B ]; then echo YES; else echo NO; fi
NO
[root@zetawiki ~]# A=2; B=3; if [ $A -lt $B ]; then echo YES; else echo NO; fi
YES


4 작거나 같다[편집]

if [ $A -le $B ]; then echo YES; else echo NO; fi
[root@zetawiki ~]# A=2; B=1; if [ $A -le $B ]; then echo YES; else echo NO; fi
NO
[root@zetawiki ~]# A=2; B=2; if [ $A -le $B ]; then echo YES; else echo NO; fi
YES
[root@zetawiki ~]# A=2; B=3; if [ $A -le $B ]; then echo YES; else echo NO; fi
YES

5 크다[편집]

if [ $A -gt $B ]; then echo YES; else echo NO; fi
[root@zetawiki ~]# A=2; B=1; if [ $A -gt $B ]; then echo YES; else echo NO; fi
YES
[root@zetawiki ~]# A=2; B=2; if [ $A -gt $B ]; then echo YES; else echo NO; fi
NO
[root@zetawiki ~]# A=2; B=3; if [ $A -gt $B ]; then echo YES; else echo NO; fi
NO

6 크거나 같다[편집]

if [ $A -ge $B ]; then echo YES; else echo NO; fi
[root@zetawiki ~]# A=2; B=1; if [ $A -ge $B ]; then echo YES; else echo NO; fi
YES
[root@zetawiki ~]# A=2; B=2; if [ $A -ge $B ]; then echo YES; else echo NO; fi
YES
[root@zetawiki ~]# A=2; B=3; if [ $A -ge $B ]; then echo YES; else echo NO; fi
NO

7 같이 보기[편집]

8 참고[편집]

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