스크립트 작성할 때 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 |
반응형
'Language > SHELL' 카테고리의 다른 글
[SH] 파일에서 grep한 결과를 파싱하여 처리 (3168) | 2015.07.03 |
---|---|
[SH]명령어가 존재하는지 확인 후 없으면 찾아서 세팅 (3483) | 2015.07.03 |