If statement not working

I understand this question probably poses some child like stupidity, but I can't get this if statement to work for love or money.

#!/bin/ksh
echo "Input either 1 or 2"
read Num
if [$Num -eq 1 ]; then
echo "Message 1"
if [$Num -eq 2 ]; then
echo "Message 2"
else
echo "false"
fi

$ ksh decisions
Input either 1 or 2
2
decisions[4]: syntax error at line 4 : `then' unmatched

Yes, numerous problems!

Indenting helps expose the problems....

#!/bin/ksh

echo "Input either 1 or 2"
read Num

if [ $Num -eq 1 ]
then
        echo "Message 1"
else
        if [ $Num -eq 2 ]
        then
                echo "Message 2"
        else
                echo "false"
        fi
fi

Still getting an error when running it:

$ ksh decisions
Input either 1 or 2
2
decisions[5]: [2: not found
decisions[9]: [2: not found
false

That is because you missed the space between the [ and $ in the if statements.

That's brilliant, thank you!

I would also advice you to put double-quotes around all uses of $Num (ie. "$Num"), to ensure you have an empty string rather than a missing variable if the responder just presses Enter.

Either that or - IMHO even better - typeset the variable instead of taking it out of nowhere:

#! /bin/ksh

typeset -i Num=0

# ... rest of the code ...

bakunin