Chuck B Ihekwaba
Chuck B Ihekwaba

Reputation: 69

In Mac terminal, why does this code give me "command not found", "syntax error near unexpected token", and " 'then'?

read command;

if[ $command = "make"]
then
    echo "Hello"
elif[ $command = "make run"]
then 
    echo "Goodbye"
fi

I have looked at similar questions and their solutions are not helping here.

Upvotes: 1

Views: 109

Answers (1)

Derick Alangi
Derick Alangi

Reputation: 1100

You need to respect spaces in bash scripts like @Jonny Henly said. Here is a modified version of your code, try it and see if it works.

read command;

if [ $command = "make" ]
then
    echo "Hello"
elif [ $command = "make run" ]
then 
    echo "Goodbye"
fi

Hope it helps.

Upvotes: 4

Related Questions