Help with KSH Script Variables

Saint Nick

Lifer
Jan 21, 2005
17,722
6
81
This doesn't work...I don't know why!

Code:
#! /usr/bin/ksh
month=$1        
        if [ $month -lt 10 ] ; then
            month = "0${month}"
            #echo $month
        else
            echo $month
        fi
It is essentially a bit of code to add zeros to the beginning of any number less than 10. Everything else aside, why does it give me this error?

Code:
./test[4]: month:  not found
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,703
4,661
75
My guess: you shouldn't put spaces around the "=".
 

Saint Nick

Lifer
Jan 21, 2005
17,722
6
81
Well that is silly...the rest of my script has variables and are assigned successfully even with the spaces present. I wonder what gives? Oh well...thanks for the help Ken!
 

Saint Nick

Lifer
Jan 21, 2005
17,722
6
81
So is there some sort of best practice with scripting then in regards to the operators? Should you just always eliminate spaces?

Thanks for the link Crusty