Video
Notes
- Basic syntax:
mynum=200
if [ $mynum -eq 200 ]
then
echo "The condition is true."
else
echo "The condition is false."
fi
- Checks within single brackets
- Between variables/literals
- Comparing integers
-eq (equal to)
-ne (not equal to)
-gt (greater than)
-ge (greater than or equal)
-lt (less than)
-le (less than or equal)
- Comparing strings
= (equal to)
!= (not equal to)
- Comparing files
-nt (newer than)
-ot (older than)
- Before the variable/literal
-f (regular file exists)
-d (directory exists)
-n (string has non-zero length)
-z (string has length zero)
- Combining checks
- Checks without brackets
command -v COMMAND (command exists)
COMMAND (command exits with return code 0)
! reverses the following condition