|
How to Evaluate an Expresion in Shell Scripting Language |
|
|
|
Next example evaluates if a=100, and if is true, it will echo a:
If evaluation example #!/bin/sh a=100 if [ "$a" -eq 100 ] then fi
Here are some evaluation operators (comparissons): -eq --- is equal to -ne --- is not equal to -gt --- is greater then -ge --- is greater then or equal to -lt --- is less then -le --- is less then or equal to = --- is equal to, valid for string comparisons.
File operations (verify if): -f --- file exists and is not a directory -d --- directory exists -s --- file exists and is not empty -x --- file is executable -r --- file is readable -w --- file is writable
The followig example print "File exists" message, if a file install.log exists in the same directory as the script:
example2.sh #!/bin/sh echo "Now I will verify if file install.log exists:" if [ -f "install.log" ] then fi
|