Relational Operators: Show Examples
Relational Operators: Show Examples
Bourne Shell supports the following relational operators that are specific to numeric
values. These operators do not work for string values unless their value is numeric.
For example, following operators will work to check a relation between 10 and 20 as
well as in between "10" and "20" but not in between "ten" and "twenty".
Assume variable a holds 10 and variable b holds 20 then −
Show Examples
-eq Checks if the value of two operands are [ $a -eq $b ] is not true.
equal or not; if yes, then the condition
becomes true.
String Operators
The following string operators are supported by Bourne Shell.
Assume variable a holds "abc" and variable b holds "efg" then −
Show Examples
-b file Checks if file is a block special file; if yes, then [ -b $file ] is false.
the condition becomes true.
-d file Checks if file is a directory; if yes, then the [ -d $file ] is not true.
condition becomes true.
-g file Checks if file has its set group ID (SGID) bit [ -g $file ] is false.
set; if yes, then the condition becomes true.
-k file Checks if file has its sticky bit set; if yes, then [ -k $file ] is false.
the condition becomes true.
-p file Checks if file is a named pipe; if yes, then the [ -p $file ] is false.
condition becomes true.
-u file Checks if file has its Set User ID (SUID) bit set; [ -u $file ] is false.
if yes, then the condition becomes true.
-s file Checks if file has size greater than 0; if yes, [ -s $file ] is true.
then condition becomes true.
C Shell Operators
Following link will give you a brief idea on C Shell Operators −
C Shell Operators