I have the code below and am receiving the following error output:
Enter your exam score
40
./if2.sh: line 6: 40: No such file or directory
Very well done. You have an A grade.
I'm using bash 4.1.2(1) on CentOS.
#!/bin/bash
#This script demonstrates the if-then-elif format.
echo "Enter your exam score"
read exam_pct
if [ $exam_pct < 40 ]
then
echo "Sorry, you have failed."
elif [ $exam_pct > 70 ]
then
echo "Very well done. You have an A grade."
else
echo "Well done. You passed."
fi
What's wrong here?
[is a command. Shell scripts are much clearer if it is spelled correctly, and the correct spelling istest. When you writeif test $exam_pct < 40is is much more obvious that you are trying to invoke the commandtest $exam_pctwith input redirected from the file40.