Skip to content

Commit

Permalink
Create eg_ifel.sh
Browse files Browse the repository at this point in the history
Special: 600 commits total. Milestone.
  • Loading branch information
XuhuaHuang committed Oct 31, 2021
1 parent a566c14 commit 5f77c98
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions BashExample/eg_ifel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Commonly used commands with this file:
# bash --version
# cat eg_ifel.sh
# bash eg_ifel.sh

age=0 # initialize a variable age to 0
# Provide instruction and ask for user input
echo -n 'Pleaes enter your age: '
read age
# Ouput to terminal
printf 'You claimed to be %d years old.\n' $age

# Determine the range of age
if [ ${age} -lt 18 ]; then
echo 'You are under 18 years old.'
elif [ ${age} -eq 20 ]; then
echo 'You may get popcorn because you are 20.'
else
echo 'You may proceed.'
exit 1
fi

echo 'This line may not be executed.'

# -gt (greater than) >
# -ge (greater or equal to) >=
# lt (less than) <
# -le (less than or equal to) <=
# -eq (equal to) ==
# -nq (not equal to) !=

0 comments on commit 5f77c98

Please sign in to comment.