Skip to content

Commit ef94422

Browse files
authored
Update III Control Statements in Bash Scripting.py
1 parent bba218f commit ef94422

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Introduction to Bash Scripting/III Control Statements in Bash Scripting.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,51 @@
22
You’ll learn the differences between FOR, WHILE, IF, and CASE statements and how to use them in your Bash scripts.
33
Armed with these new tools, you’ll be ready to create more advanced Bash scripts with conditional logic.
44
"""
5+
"""
6+
*** IF statements
7+
8+
*** sytax
9+
>>>>>> if [ condition ]; then
10+
# some code
11+
else
12+
# some other code
13+
fi
14+
15+
# double parethesis structure
16+
eg:
17+
if (($x > 5)); then
18+
echo "$x is more than 5!"
19+
fi
20+
21+
# square brackets and arithmetic flags structure
22+
>>>>>> -eq : 'equal to'
23+
>>>>>> -ne : 'not equal to'
24+
>>>>>> -lt : 'less than'
25+
>>>>>> -le : 'less than or equal to'
26+
27+
eg:
28+
if [ $x -gt 5 ]; then
29+
echo "$x is grater than 5!"
30+
fi
31+
32+
*** bash Conditional Flags
33+
>>>>>> -e : 'file exists'
34+
>>>>>> -s : 'if exists and it's grater than zero'
35+
>>>>>> -r : 'if exists and readable'
36+
>>>>>> -w : 'if exists and writable'
37+
38+
*** AND OR in bash
39+
>>>>>> && : 'and'
40+
>>>>>> || : 'or'
41+
42+
eg:
43+
# Simple-square notation
44+
if [ $x -gt 5 ] && [ $x -lt 11 ]; then
45+
echo "$x more than 5, less than 11"
46+
fi
47+
48+
# Double-square notation
49+
if [[ $x -gt 5 && ]]; then
50+
echo "$x more than 5, less than 11"
51+
fi
52+
"""

0 commit comments

Comments
 (0)