Skip to content

Commit 5f77c98

Browse files
committed
Create eg_ifel.sh
Special: 600 commits total. Milestone.
1 parent a566c14 commit 5f77c98

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

BashExample/eg_ifel.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Commonly used commands with this file:
4+
# bash --version
5+
# cat eg_ifel.sh
6+
# bash eg_ifel.sh
7+
8+
age=0 # initialize a variable age to 0
9+
# Provide instruction and ask for user input
10+
echo -n 'Pleaes enter your age: '
11+
read age
12+
# Ouput to terminal
13+
printf 'You claimed to be %d years old.\n' $age
14+
15+
# Determine the range of age
16+
if [ ${age} -lt 18 ]; then
17+
echo 'You are under 18 years old.'
18+
elif [ ${age} -eq 20 ]; then
19+
echo 'You may get popcorn because you are 20.'
20+
else
21+
echo 'You may proceed.'
22+
exit 1
23+
fi
24+
25+
echo 'This line may not be executed.'
26+
27+
# -gt (greater than) >
28+
# -ge (greater or equal to) >=
29+
# lt (less than) <
30+
# -le (less than or equal to) <=
31+
# -eq (equal to) ==
32+
# -nq (not equal to) !=

0 commit comments

Comments
 (0)