Basic Operators in Shell Scripting

Logical Operator or Boolean Operator:
&&	-a	{Logical AND}: Execute the command when both conditions are true
||	-o	{Logical OR}: Any of one condition will work.
!	!	{Not equal to}: Negates the result of the condition. 

Note: If you will use “-a, -o, !” you need to use [ ] in condition while using for “&&, ||, !” you need to use [[ ]]. 
String Operator:
==	{Equal to}: Check if two strings are equal. 
!=	{Not equal to}: Check if both strings are nt equal. 
-z	{zero length string}: Check if mentioned strings has zero length.
-n	{non zero length string}: Check if string is non zero in length.
Relational Operator:
-eq	==	{equal to}: Check if two strings are equal.

-ne	!=	{Not equal to}: Check if two strings are not equal.

-lt	<	{less than}: Check if left is less than right.

-gt	>	{greater than}: Check if left is greater than right.

-le	<=	{less than equal to}: Check if left is less than equal to right. 

-ge	>=	{greater than equal to}: Check if left is greater than equal to right.
File Testing Operator:
-e	filename	{is it exists}

-f	filename	{is it a regular file}

-b	filename	{file is block special file or not}

-c 	filename	{file is character	 special file or not}

-d 	filename	{is it a directory}

-r	filename	{is it readable file}

-w 	filename	{is it writable file}

-x	filename	{is it executable file}

-s	filename	{check size of file}
Arithmetic Operators:
+		Addition

-		Subtraction

*		Multiplication

/		Division

%		Modules

++		Increment Operator

--		Decrement Operator
Note: Below is the value which are vastly used in script.

0 - True,
1 - False

Leave a Reply

Your email address will not be published. Required fields are marked *