Operator in shell scripting

An operator in shell scripting

In this article, we will see some operator of shell scripting. such as Arithmetic Operators, Relational Operators, Boolean Operators, String Operators, File Test Operators.



There are various operators supported by each shell. We will discuss in detail about Bourne shell (default shell) in this chapter.

-eq - is equal to
-ne - is not equal to
-gt - is greater than
-ge - is greater than or equal to
-lt - is less than
-le - is less than or equal to
< - is less than -  (($a < $b))
<= - is less than or equal to - (($a <= $b))
> - is greater than - (($a > $b))
>= - is greater than or equal to - (($a >= $b))





string comparison

= - is equal to
== - is equal to
!= - is not equal to
< - is less than, in ASCII alphabetical order - [[$a < $b]]
> - is greater than, in ASCII alphabetical order - [[$a > $b]]
-z - string is null, that is , has zera length


#! /bin/bash

#arithmetic operations

people=10

man=6

women=9

echo $(( people + man + women ))

echo $(expr $people + $man + $women )

echo $(( people + man * women ))

echo $(( people / man + women ))

echo $(( people + man - women ))

Output:

25 25 64 10 7

Share:

0 comments

Please leave your comments...... Thanks