Ass 03
Ass 03
name="John"
num=25
Accessing Variables:
echo "Name: $name"
echo "Number: $num"
Using expr
result=$(expr 5 + 3)
Logical Operators:
&&: logical AND
||: logical OR
case variable in
pattern1)
# commands to execute if variable matches pattern1
;;
pattern2)
# commands to execute if variable matches pattern2
;;
*)
# commands to execute if variable doesn't match any pattern
;;
esac
echo "Enter a day (Monday, Tuesday, etc.):"
read day
case $day in
Monday)
echo "Start of the work week."
;;
Tuesday)
echo "Second day of the work week."
;;
Wednesday)
echo "Midweek."
;;
Thursday)
echo "Almost the weekend."
;;
Friday)
echo "Last day of the work week."
;;
Saturday | Sunday)
echo "It's the weekend!"
;;
*)
echo "Invalid day."
;;
esac
While loop
while [ condition ]
do
# commands to be executed repeatedly
done
Example:
count=1