comparing variables in an if statement

#!/bin/bash
#timetest
TIMENOW="$(date)"
T1=12:00:00
echo $TIMENOW >timenow
cat timenow |cut -f4 -d' ' >time1
T2=$(sed -n "${1}p" time1)
echo "T1 = " $T1
echo "T2 = " $T2
if[ $T1 -gt $T2 ] then
  echo $T1 
 else
  echo $T2 
fi

I thought scripting was simple! So why does this script result in:

T1 =  12:00:00
T2 =  16:04:43
/home/admin/user/bin/timetest: line 10: if[ 12:00:00 -gt 16:04:43 ]: command not found
12:00:00
/home/admin/user/bin/timetest: line 12: syntax error near unexpected token `else'
/home/admin/user/bin/timetest: line 12: ` else'

You are getting the command not found message because you need a space between the 'if' and the open bracket:

if [ $T1 -gt $T2 ] then

You will also likely receive an error once you fix that as '-gt' implies integer comparison, and your variables contain non-numeric chaaracters (colons). You might consider something like this:

t1="12000000"
t2="$(date "+%H%M%S")"
if [ $t1 -gt $t2 ]
then
    echo true
else
    echo false
fi

Both timestamps are created without colons and can be compared as integers.

Thank you for the replies. The placement of 'then' was important as was the space after 'if' ........Thank you, Agama! However I still needed further modification. Here is the script that works:

#!/bin/bash
#timetest
TIMENOW="$(date)"
T1=12:00:00
echo $TIMENOW >timenow
cat timenow |cut -f4 -d' ' >time1
T2=$(sed -n "${1}p" time1)
echo "T1 = " $T1
echo "T2 = " $T2
if [[ $T1 < $T2 ]] #or [ $T1 \< $T2 ] for comparing ascii strings
 then
  echo $T1 
 else
  echo $T2 
fi

Good. I still think you are going through more work than needed to get T2. All that effort of cutting, echoing and tmp files isn't needed:

T2=$( date "+%H%M%S" )    # without colons
T2=$( date "+%X" )              # hr:min:sec

Thank you! I was concentrating so hard on the 'if' I neglected the more obvious......Thanks again.