-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.sh
More file actions
57 lines (49 loc) · 1.41 KB
/
operators.sh
File metadata and controls
57 lines (49 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
val=`expr 2 + 2`
echo "Total value : $val"
a=20
b=10
add=`expr $a + $b`
sub=`expr $b - $a`
mul=`expr $a \* $b`
div=`expr $b / $a`
mod=`expr $b % $a`
equality=`expr [ $b == $a ]`
notequal=`expr [$b != $a]`
assigment=`expr a = $b`
echo "Addition : $add"
echo "Subtraction : $sub"
echo "Multiplication : $mul"
echo "Division : $div"
echo "Modulus : $mod"
echo "Equality : $equality"
echo "Not Equal : $notequal"
echo "Assignment : $assigment $a $b"
equal=[ $b -eq $a ]
notequal2=`expr [ $b -ne $a ]`
greaterthan=`expr [ $b -gt $a ]`
lessthan=`expr [ $b -lt $a ]`
greaterthanequal=`expr [ $b -ge $a ]`
lessthanequal=`expr [ $b -le $a ]`
echo "Equality(relational) : $equal"
echo "Not Equal : $notequal2"
echo "greater than : $greaterthan"
echo "less than : $lessthan"
echo "greater than equal : $greaterthanequal"
echo "less than equal : $lessthanequal"
#Boolean Operators
#logical negation
#[ ! false ] is true.
#logical OR
#[ $a -lt 20 -o $b -gt 100 ] is true.
#logical AND
#[ $a -lt 20 -a $b -gt 100 ] is false.
#String Operators
#[ $a = $b ] is not true.
#[ $a != $b ] is true.
#Checks if the given string operand size is zero; if it is zero length, then it returns true.
#[ -z $a ] is not true.
#Checks if the given string operand size is non-zero; if it is nonzero length, then it returns true.
#[ -n $a ] is not false.
#Checks if str is not the empty string; if it is empty, then it returns false.
#[ $a ] is not false.