-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable_types.bash
More file actions
98 lines (66 loc) · 1.25 KB
/
variable_types.bash
File metadata and controls
98 lines (66 loc) · 1.25 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# String
string_v="This is a string"
# Integers
number_one=1
number_two=10
# If you want to do arithmetic operations use let expr o $(()) expressions
# let
let plus=number_one+number_two
echo "$plus"
# expr
plus=$(expr $number_one + $number_two)
echo "$plus"
# $(())
plus=$(( $number_one + $number_two))
echo "$plus"
# Define an environment variable
export MY_VARIABLE="IM AN ENVIRONMENT VARIABLE"
echo "$MY_VARIABLE"
unset "$MY_VARIABLE"
# Operators
# + PLUS
# - SUSTRAC
# * MULTIPLY
# / DIVISIONi
# % MODULE
# Examples...
a=10
b=5
echo $(( a + b ))
echo $(( a - b ))
echo $(( a * b ))
echo $(( a / b ))
echo $(( a % b ))
# Comparisson operators
# -eq (same as)
# -ne (not same as)
# -lt (lower than)
# -le (lower or equally to)
# -gt (bigger than)
# -ge (bigger or equally to)
# Examples...
if [ $a -eq $b ]; then
echo "a and b has the same value"
else
echo "a and b doesn't has the same value"
fi
if [ $a -gt $b ] then
echo "a it's bigger than b"
fi
# Logical operators
# && (AND)
# || (OR)
# ! (NOT)
# Examples...
# AND
if [ $a -gt 0 ] && [ $b -gt 0 ]; then
echo "a and b are bigger than 0"
fi
# OR
if [ $a -gt 0 ] || [ $b -gt 0 ]; then
echo "a or b are bigger than 0"
fi
# NOT
if ! [ $a -lt 0]; then
echo "a it's not lower than 0"
fi