title: "set -o noglob" in bash shell script
body: <p>I would usually write <code>SQL</code> statements inline in a Bash shell script to be executed in <code>SQLPlus</code> as-</p>
  
  <pre><code>#! /bin/sh
  
  sqlplus user/pwd@dbname&lt;&lt;EOF
  insert into dummy1 
  select * from dummy2;
  
  commit;
  exit;
  EOF
  </code></pre>
  
  <p>This would work just fine and will insert rows into <code>dummy1</code> when executed. A colleague of mine came to me the other day with a script like below (simplified)</p>
  
  <pre><code>#! /bin/sh    
  sqlvar="insert into dummy1 select * from dummy2;commit;"    
  echo $sqlvar|sqlplus user/pwd@dbname
  </code></pre>
  
  <p>The issue with this is when executed the variable <code>sqlvar</code> expands the <code>*</code> to be all the files in the current directory and would eventually error out like-</p>
  
  <pre><code>SQL&gt; insert into dummy1 select &lt;--all the file names in the current directory--&gt; 
  from dummy2;commit
                                                      *
  ERROR at line 1:
  ORA-00923: FROM keyword not found where expected
  </code></pre>
  
  <p>Our first stance on this one was the shell was interpreting <code>*</code> in a wildcard context and listing all the file names while the shell variable expansion (not quite sure why....???). So, in order to understand this we did something like below-</p>
  
  <pre><code>$ var="hello *"
  $ echo $var
  hello &lt;--all the file names in the current directory--&gt;
  </code></pre>
  
  <p>But</p>
  
  <pre><code>$*
  ksh: somefile.sh: 0403-006 Execute permission denied. #since it had no execute permission
  </code></pre>
  
  <p>There are a number of other files in the directory and I am not sure why <code>*</code> chose to execute <code>somefile.sh</code> or is pointed to <code>somefile.sh</code>.</p>
  
  <p>After, a bit of digging we realized, using <code>set -o noglob</code> would resolve this issue entirely, like-</p>
  
  <pre><code>#! /bin/sh
  set -o noglob
  sqlvar="insert into dummy1 select * from dummy2;\n commit;"    
  echo $sqlvar|sqlplus user/pwd@dbname
  </code></pre>
  
  <p>There are some conflicting or rather contradictory description of <code>set</code>ting <code>noglob</code>, over the internet. So I am looking if someone could explain the knick knacks of this bit.</p>