Command not found when running a script- variable does not seem to register

Viewed 34

I am trying to create a simple script whereby I compare a user input (bday) and compare it with the current date in a certain format.

The result I get is that [$bday..] command not found?

Would appreciate the help on this, with an explanation

#!/bin/bash

echo please enter your bday YYYY-MM-DD
read bday
dates=$(date +%F)
echo $dates

if [$bday == $dates]
then
 echo Happy Birthday
else
 echo Happy not Birthday
fi

#strip $date of day-month-year integers only
#arrange into YYY-MM-DD
#compare the two
#date --help```
1 Answers

Your line here is missing whitespace.

if [$bday == $dates]

Here the shell is searching for a command named [$bday which doesn't exist and throws an error. It should instead be

if [ $bday == $dates ]

Related