7.1 test dan operator
test is sh shell utility that used to check information about a file and used to compare both string or numeric.
syntax:
test expresion
test work proses is return the status information with 0 value (correct) or 1 (false) where this value status can be read by special variable $.
[elvin@TestBed$]test 7 -gt 3 [elvin@TestBed$]echo $? 0
This statement 7 -gt (greather than) 3 is being evaluated test return 0 for variable status $.
This mean this statement is true.
if we compare with below expresion
[elvin@TestBed$]test 3 -lt 1 [elvin@TestBed$]echo $? 1
this status value is 1, which mean false statement
if you see the symbol -gt and -lt, this want mean operator.
simple operator is special character that do operation for a few operand, example 2+3.
"+" is an operator. 2 and 3 is an operand.
for test example, the operator is -lt and -gt, and the number is on left and the operand is on the right.
Below is the operator that bash can be used:
Operator | Information |
bil1 -eq bil2 | return true if bil1 is same as bil2 |
bil1 -ne bil2 | return true if bil1 is not same as bil2 |
bil1 -lt bil2 | return true if bil1 is less than bil2 |
bil1 -le bil2 | return true if bil1 is less than enough bil2 |
bil1 -gt bil2 | return true if bil1 is greater than bil2 |
bil1 -ge bil2 | return true if bil1 is greater than enough bil2 |
7.1.2. Operasi string
Operator | Information |
-z STRING | return true if STRING length is zero |
STRING1 == STRING2 | return true if STRING1 is same as STRING2 |
7.1.3 Operator file
Operator | Information |
-f FILE | return true if FILE is exist and is a normal file |
-d FILE | return true is FILE is exist and is a directory |
7.1.4 Operator logic
ekspr1 -o ekspr2 | return true is one of the expression is true (or,||) |
ekspr1 -a ekspr2 | return true is expression 1 and expression 2 true(and,&&) |
! ekspresi | return true if the expression is false (not!) |
0 comments:
Post a Comment