title: Why doesn't bash history expansion work in functions?
body: <p>When I'm programming, I'll find myself cycling through the same three shell commands, e.g:</p>
  
  <ol>
  <li><code>vim myGraphic.cpp</code></li>
  <li><code>g++ -lglut -lGLU myGraphic.cpp -o prettyPicture</code></li>
  <li><code>./prettyPicture</code></li>
  </ol>
  
  <p>In order to avoid hitting the uparrow key thrice every time, I put the following in my bashrc:</p>
  
  <pre><code>function cyc { 
      CYCLE=3
      !-$CYCLE 
  }
  </code></pre>
  
  <p>When I use the 'cyc' function, however, I get the error </p>
  
  <blockquote>
    <p>"bash: !-3: command not found". </p>
  </blockquote>
  
  <p>This technique of history expansion works interactively with the shell, but it does not seem to work with function definitions. What is the explanation for this difference? How might I make a function equivalent to 'cyc' that works?</p>