For loop in if clause. If clause is not calling
<p>I am new to the Shell, and trying to write few simple scripts.</p>

<p>Its not invoking <code>if</code> clause here or not calling <code>for</code> loop. I have shared the o/p</p>

<pre><code>#!/bin/bash

set -x
read -p "enter Date in DD " d
if [$d -gt "00" -a $d -lt "31"]
then
     echo "Choose any one month from given option: Jan,Feb,Mar,Apr,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
     read  m
     for $m  in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
      do
        case "echo $m" in
        Jan) mnum=01;;
        Feb) mnum=02;;
        Mar) mnum=03;;
        Apr) mnum=04;;
        May) mnum=05;;
        Jun) mnum=06;;
        Jul) mnum=07;;
        Aug) mnum=08;;
        Sep) mnum=09;;
        Oct) mnum=10;;
        Nov) mnum=11;;
        Dec) mnum=12;;
      esac
echo "Month is $mnum"
   done
else  echo "Its an invalid Date"
fi
    echo "Enter Year in YYYY"
     read y
   if echo $y |egrep "^[1|2][0-9][0-9]+$"
   then
    echo "Its Valid year"
    echo "Your date is $d/$m/$y"
   fi
~
</code></pre>

<p><strong>Output:</strong></p>

<pre><code> ./a.sh
+ read -p 'enter Date in DD ' d
enter Date in DD 23
+ '[23' -gt 00 -a 23 -lt '31]'
./a.sh: line 5: [23: command not found
+ echo 'Its an invalid Date'
Its an invalid Date
+ echo 'Enter Year in YYYY'
Enter Year in YYYY
+ read y
2015
+ echo 2015
+ egrep '^[1|2][0-9][0-9]+$'
2015
+ echo 'Its Valid year'
Its Valid year
+ echo 'Your date is 23//2015'
Your date is 23//2015
</code></pre>