Operators
test
Syntax
- test <test-expr>
- [<whitespace> <test-expr> <whitespace>]
Usage
- <test-expr> = <test-expr> <-a,-o> <test-expr>
- <test-expr> = <value1> <operator> <value2>
- <test-expr> = <operator> <value2>
File test operators
- Compares two values
- -d : File is a directory
- -e : File exists
- -L : File is a symbolic link
- -r : File is readable
- -w : File is writeable
- -x : File is executable
Relational test operators (for comparing integer values)
- -nt : File1 is newer than file2
- -ot : File1 is older than file2
Additional test operators
- -eq : Equal
- -ne : Not equal
- -lt : Less than
- -le : Less than or equal
- -gt : Greater than
- -ge : Greater than or equal
- = : True if the strings are equal
- != : True if the strings are not equal
- ! : True if test is false
- -a : True if both test1 and test2 are true
- -o : True if either test1 or test2 are true
Examplesif [ -e data.txt ]; then
echo "File exists"
fi
let
SyntaxUsage
- let [<varname> =] <value1> <operator> <value2>
Examples
- Blank spaces can only be used if the expression is in double quotes.
- In an expression of the form let 1+2, the value of the expression is sent to standard output.
let arg=arg+1
let "var = arg * 3"
index="3"
while let "index > 0"; do
echo while: $index
let index=index-1
done