title: Bash shell script error sh: [: missing `]'
body: <p><strong>Aim:</strong></p>
  
  <p>I'm trying to create a useful shortcut for initializing a git repo locally, and simultaneously creating a remote repo origin on bitbucket or github. This function is added to my <code>.bashrc</code> file in my home directory.</p>
  
  <p><strong>Here is the bash function (which yields an error):</strong></p>
  
  <pre><code>function initg() {
   # Defaults to bitbucket API
   local API="https://api.bitbucket.org/1.0/repositories/"
   local DATA="name=$3&amp;description=$4&amp;is_private=true&amp;scm=git"
   local REMOTE="ssh://git@bitbucket.org/$2/$3"
  
   # Use github if specified
   if [ "$1" == "gh" ]; then
        API="https://api.github.com/user/repos"
        DATA='{"name":"$3", "description": "$4"}'
        REMOTE="git@github.com:$2/$3"
   fi
  
   if [ -z "$API" ] || [ -z "$DATA" ] || [ -z "$REMOTE" ] || [ -z "$2" ]
   then
        echo "A parameter is missing or incorrect"
   else
        curl -X POST -u $2 ${API} -d ${DATA}
        git init
        git add .
        git commit -m "Created repo"
        git remote add origin $REMOTE
        git push -u origin master
   fi
  }
  </code></pre>
  
  <p><strong>The error:</strong></p>
  
  <pre><code>username@COMPUTER-NAME /path/to/local/repo
  $ initg gh username bash_test desc
  sh: [: missing `]'
  sh: [: missing `]'
  Enter host password for user 'username':
  </code></pre>
  
  <p><strong>My Question:</strong></p>
  
  <p>First, where is my error? Secondly, how might I improve the control flow or structure of this script to achieve the stated goals?</p>