title: A bash function definition that doesn't seem to work
body: <p>I was experimenting with shell functions the other day, with the objective of overriding the <code>ls</code> command.
  The intention was to have the shell call my <code>ls</code> function first then if the first switch is "-y" do one thing, otherwise call the regular <code>/bin/ls</code>, but the result behaves in a way I don't understand.</p>
  
  <p>To enable it I decided to use "-y" for the switch because:</p>
  
  <pre><code>$ ls -y
  ls: invalid option -- 'y'
  Try `ls --help' for more information.
  </code></pre>
  
  <p>So it can't break the core functionality of <code>ls</code>.
  Anyway, reducing the problem to its simplest, and with a couple of other examples to help highlight the problem:</p>
  
  <pre><code>$ function ls() { [[ "y$1" == "y-y" ]] &amp;&amp; echo LS ; } 
  $ function less() { [[ "y$1" == "y-y" ]] &amp;&amp; echo LESS ; }
  $ function try() { [[ "y$1" == "y-y" ]] &amp;&amp; echo TRY ; }
  </code></pre>
  
  <p>So I'm overriding <code>ls</code>, <code>less</code> and defining <code>try</code> which is like the "contol" specimen :)</p>
  
  <p>Now Invoking this way:</p>
  
  <pre><code>$ ls ; less ; try 
  </code></pre>
  
  <p>It behaves as expected (no output), but:</p>
  
  <pre><code>$ ls -y ; less -y ; try -y
  LESS
  TRY
  </code></pre>
  
  <p>the <code>ls</code> fails to work, but the <code>less</code> override does, as does the "control".</p>
  
  <p>Elsewhere on stackoverflow or askubuntu (but I've lost the reference for the minute) I saw an example  that implied <code>ls</code> was a builltin, but:</p>
  
  <pre><code>$ which ls
  /bin/ls
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>$ builtin ls
  bash: builtin: ls: not a shell builtin
  </code></pre>
  
  <p>So it doesn't seem to be on my system (and even if it was I can't actually see why it would behave like this).</p>
  
  <p>I wonder what the explanation is? It isn't important, but I'd like to understand what's going on.</p>
  
  <p>Thanks.</p>