I'm writing a shell script to take a number between 1 and 7 in the command line and return the corresponding day of the week. My code currently looks like this:
#!/bin/bash
echo "Please enter a number between 1 and 7 >"
read number
number=$n
if [ "$n"=="1" ]
then
echo "Monday"
elif [ "$n"=="2" ]
then
echo "Tuesday"
elif [ "$n"=="3" ]
then
echo "Wednesday"
elif [ "$n"=="4" ]
then
echo "Thursday"
elif [ "$n"=="5" ]
then
echo "Friday"
elif [ "$n"=="6" ]
then
echo "Saturday"
elif [ "$n"=="7" ]
then
echo "Sunday"
else
echo "error"
fi
this returns "Monday" regardless of the input. If I add spaces either side of the == then it returns "error" regardless of the input! I've tried various things but cannot work out why
Aucun commentaire:
Enregistrer un commentaire