forked from LandmakTechnology/scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
if-else-scripts.sh
88 lines (82 loc) · 1.65 KB
/
if-else-scripts.sh
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
81
82
83
84
85
86
87
88
if else statements
#ife.sh
#!/bin/sh
a=10
b=20
if [ $a == $b ]
then
echo "a is equal to b"
else
echo "a is not equal to b"
fi
#ife1.sh
#if [ $# -lt 3 ]
if (( $# == 3 ))
then
#Number of arguments on the command line.
echo '$#:' $#
#Process number of the current process.
echo '$$:' $$
#Display the 3rd argument on the command line, from left to right.
echo '$3:' $3
#Display the 10th argument on the command line, from left to right.
echo '${10}:' ${10}
#Display the name of the current shell or program.
echo '$0:' $0
#Display all the arguments on the command line using * symbol.
echo '$*:' $*
#Display all the arguments on the command line using @ symbol.
echo '$@:' $@
date
echo '$?:' $?
else
echo "Please Pass the 3 command line args along with script"
fi
#ife2.sh
#!/bin/bash
echo -n "Enter a number: "
read VAR
if [ $VAR -gt 10 ]
then
echo "The variable is greater than 10."
fi
#ife3.sh
#!/bin/bash
echo -n "Enter a number: "
read VAR
if [ $VAR -gt 10 ]
then
echo "The variable is greater than 10."
else
echo "The variable is equal or less than 10."
fi
#ife4.sh
#!/bin/bash
echo -n "Enter a number: "
read VAR
if [ $VAR -gt 10 ]
then
echo "The variable is greater than 10."
elif [ $VAR -eq 10 ]
then
echo "The variable is equal to 10."
else
echo "The variable is less than 10."
fi
#ife5.sh
#!/bin/bash
echo -n "Enter the first number: "
read VAR1
echo -n "Enter the second number: "
read VAR2
echo -n "Enter the third number: "
read VAR3
if [ $VAR1 -ge $VAR2 ] && [ $VAR1 -ge $VAR3 ]
then
echo "$VAR1 is the largest number."
elif [ $VAR2 -ge $VAR1 ] && [ $VAR2 -ge $VAR3 ]
then
echo "$VAR2 is the largest number."
else
echo "$VAR3 is the largest number."
fi