posted 18 years ago
1) divisibility.sh
-------------------
echo "Enter the number:\n"
read x
y=`expr $x % 3`
z=`expr $x % 4`
if [$y -eq 0 -a $z -eq 0]
then
echo "Divisible by both"
elif [$y -eq 0]
then
echo "Divisible by 3 only"
elif [$z -eq 0]
then
echo "Divibible by 4 only"
else
echo "Not by both"
fi
output:
--------
divisibility.sh: line 5: [0: command not found
divisibility.sh: line 8: [0: command not found
divisibility.sh: line 11: [0: command not found
Not by both
==============================================
2) greetings.sh
----------------
h=`date "+%H"`
if [$h -gt 4 -a $h -lt 11]
then
echo "Good Morning"
elif [$h -ge 11 -a $h -lt 16]
then
echo "Good Afternoon"
elif [$h -ge 16 -a $h -lt 20]
then
echo "Good Evening"
else
echo "Good Night"
fi
output:
-------
greetings.sh: line 2: [12: command not found
greetings.sh: line 5: [12: command not found
greetings.sh: line 8: [12: command not found
Good Night
i don't where the bug lies, i am using suse linux.
please explaine me the correct way