title: Compare a Bash string literal to a local variable
body: <pre><code>#!/bin/bash
  function getComment(){
      local lang=$1;
      local theComment=$2;
      if [$lang == "Java"] #Surprisingly, an error occurs here: prog.sh: line 6: [Java: command not found
      then
          echo "//"$theComment; return;
      else
          echo "Language not found!"; return;
      fi
  }
  
  getComment "Java" "Whoo!";
  
  exit $?
  </code></pre>
  
  <p>I'm writing a Bash script that compares a variable to a string literal, and I'm using <code>[$lang == "Java"]</code> (as shown above) to compare the value of <code>lang</code> to <code>"Java"</code>. However, this comparison produces the following error:</p>
  
  <pre><code>stderr:
  prog.sh: line 6: [Java: command not found
  </code></pre>
  
  <p>I've tried using <code>[$lang -eq "Java"]</code> and <code>($lang -eq "Java")</code> as well, but those statements didn't work either, and they produced exactly the same error.</p>
  
  <p>Why is this error occurring, and what is the correct way to compare a local variable to a string literal?</p>