1

This question already has an answer here:

I am trying to get this script to function correctly but I get ./passmark.sh line 7: [y command not found.

Here is my script

#!/bin/bash
# A simple script to ask a user for a pass mark and then display a grade
# the grade will be either an A, B, C, D or F
#
CONT=y
echo
while [$CONT = "y" ]
do
        echo -e "\"Please enter a pass mark: \c \""
        read MARK
        if [$MARK -ge "0" -a $MARK -lt "50"] ; then
                echo -e "\n \"F\" \n"
        elif [$MARK -ge "50" -a $MARK -lt "60"] ; then
                echo -e "\n \"D\" \n"
        elif [$MARK -ge "60" -a $MARK -lt "70"] ; then
                echo -e "\n \"C\" \n"
        elif [$MARK -ge "70" -a $MARK -lt "80"] ; then
                echo -e "\n \"B\" \n"
        elif [$MARK -ge "80" -a $MARK -lt "100"] ; then
                echo -e "\n \"A\" \n"
        else
                echo -e "\"Invalid input!!\n \""
        fi
        echo -e "\"Would you like to enter another pass mark? (y/n) \c \""
        read REPLY
        case "$REPLY" in
                n | N | no | No | NO ) CONT=n ;;
                *) ;;
        esac
echo
done 

marked as duplicate by slm Oct 16 '14 at 22:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Take a look at shellcheck.net – Cyrus Oct 16 '14 at 22:10
  • You can also run /bin/bash -x ./script to have bash show you what it's parsing as it runs. What it tried will have a + in front of it, followed by any output. If you see an error, it's the line above. That's just for general guidance, the answer by Barmar is the cause of the error you're getting. – Tim Post Oct 16 '14 at 22:58
5

You need spaces around the [ and ], e.g.

if [ "$MARK" -ge 0 -a "$MARK" -lt 50 ]; then

The way you wrote it, when $MARK is 7, it tries to execute the [7 command instead of passing 7 as an argument to the [ command ([ is just a short name for test).

You should also quote the variable. Otherwise, if the user enters a blank line or multiple words, the test expression will not be parsed correctly.

Not the answer you're looking for? Browse other questions tagged or ask your own question.