title: Script gives "unexpected error near elif [ $1 = "-h" ] while syntax is correct
body: <p>While trying to run this command in the terminal:</p>
  
  <pre><code>gerard@yoda ~$ Sources/Scripts/ultimate.sh -u -typecount -std /usr/bin py
  Sources/Scripts/ultimate.sh: line 28: syntax error near unexpected token `elif'
  Sources/Scripts/ultimate.sh: line 28: `elif [ $1 = "-h" ];'
  </code></pre>
  
  <p>this is the source of the script:</p>
  
  <pre><code>#!/bin/bash
  
  ## $1 = Mode(u/h) ; $2 = Command(?) ; $3+ = Params
  
  if [ $1 = "-u" ];
      if [ $2 = "-typecount" ];
      then
          if [ $3 = "-std" ];
          then
              find $4 -maxdepth 1 -iname *.$5 | wc -l
          elif [ $3 = "-ext" ];
          then
              find $5 -maxdepth $4 -iname *.$6 | wc -l
          else
              echo 'use option -std for single-dir'
              echo 'or option -def for recusive with custom depth'
              echo 'filetype should be defined  type  instead of .type'
          fi
      elif [ $2 = "-prep" ];
      then
          sed -i 's/^/$3/' $4
      elif [ $2 = "-app" ];
      then
          sed -i 's/$/$3/' $4
      else
          echo 'No command specified/Command not found'
      fi
  elif [ $1 = "-h" ];
  then
      if [ $2 = "-typecount" ];
      then
          echo 'for -std: [location] [type]'
          echo 'for -ext: [depth] [location] [type]'
      elif [ $2 = "-prep" ];
      then
          echo '[text] [file]'
      elif [$2 = "-app" ];
      then
          echo '[text] [file]'
      else
          echo 'No command specified/Command not found'
  else
      echo 'No mode specified/Wrong mode'
  fi
  </code></pre>
  
  <p>The syntax appears correct to me, and a simpler version of the script, with same elif construction works fine. What did I do wrong? (the script needs to quit after the desired function is parsed)</p>