스크립트 작성할 때 if 조건문의 옵션들..
문법
#!/bin/sh
if [ -f "$1" ]
then
echo "$1 is a file"
else
echo "$1 is not a file"
fi
String Comparison | Description |
---|---|
Str1 = Str2 | Returns true if the strings are equal |
Str1 != Str2 | Returns true if the strings are not equal |
-n Str1 | Returns true if the string is not null |
-z Str1 | Returns true if the string is null |
Numeric Comparison | Description |
expr1 -eq expr2 | Returns true if the expressions are equal |
expr1 -ne expr2 | Returns true if the expressions are not equal |
expr1 -gt expr2 | Returns true if expr1 is greater than expr2 |
expr1 -ge expr2 | Returns true if expr1 is greater than or equal to expr2 |
expr1 -lt expr2 | Returns true if expr1 is less than expr2 |
expr1 -le expr2 | Returns true if expr1 is less than or equal to expr2 |
! expr1 | Negates the result of the expression |
File Conditionals | Description |
-d file | True if the file is a directory |
-e file | True if the file exists (note that this is not particularly portable, thus -f is generally used) |
-f file | True if the provided string is a file |
-g file | True if the group id is set on a file |
-r file | True if the file is readable |
-s file | True if the file has a non-zero size |
-u | True if the user id is set on a file |
-w | True if the file is writable |
-x | True if the file is an executable |
반응형
'엔지니어' 카테고리의 다른 글
PERL 아파치 로그 정규식 라이브러리 (477) | 2016.01.27 |
---|---|
PERL 확장자 *.pm *.pl 차이 (1156) | 2016.01.27 |
ctags를 cpp에서 사용하려면 (457) | 2015.11.19 |
리눅스에서 가장 많은 CPU를 사용하는 프로세스 찾는 명령 (438) | 2015.08.06 |
tr 사용해서 파일에서 개행문자 전부 제거하기 (461) | 2015.08.04 |