![]() |
My Top 3 |
![]() |
In the shell programming, are used for performing tests by
- evaluating and comparing integers or strings
- testing file attributes
Testing Conditional expressions is done by using the following three different forms of syntax.
These expressions will return an exit status of 0 for true and 1 for false. It is preferrable to use command, as it will result in fewer syntax errors.
Example :
To compare two integers, by checking if one is less than the other with one of the following :
You can also combine two or more expressions using the following operators
- Double ampersand, && ( which means “AND” )
- Double Pipe, || (which means “OR”)
the syntax for for compound expressions using || is :
If you would like to test student’s subject mark with minimum required mark and print pass if either of the subject is more than the required score, the sample code would be
-z true if length is zero
-n will be true if the string is not zero
-o will be true if option is set
example:
if [[ -z $StringA ]]; then
print “Length is zero”
fi
[[ string1 = string2 ]]
Example :
[[ $Subject = “MATH A” ]] && print “Optional Subject”
=, !=, < , >
-a (file exists)
-d (file is a dir)
-f (file is regular file)
-r (file readable)
-w (file writable)
-x (file executable)
-s (file non-empty)
-u (file has userID bit set)
[[ file1 -ef file2]] for same files
[[ file1 -nt file2]] for finding new file
[[ file1 -ot file2]] for finding older file
-eq, -ne, -le, -ge, -gt



Leave a Reply