title: How to get second-to-last argument from previous bash command? (in an interactive bash shell)
body: <p>How can I easily get the second-to-last (penultimate) word/argument from the previous command in a bash interactive shell?  I often run commands in the background, and I would like to get the file that was specified before the <code>&amp;</code>, e.g.,</p>
  <pre><code>  % echo foo &gt; /tmp/foo &amp;
    % cat !$
    % &amp;
  </code></pre>
  <p>In the example above, <code>!$</code> gives the last word, <code>&amp;</code>.  But I want the second-to-the-last argument, <code>/tmp/foo</code></p>
  <p><br><br>
  Note that it is possible to use word designators with a range like <code>!-1:3</code>, but this is impractical for a command with a large number of words where it's not quickly obvious how many words there are, e.g.,</p>
  <pre><code>% (set -x; date; pwd; git status; git diff;  git log | tail -30; date; args=--verbose time make test; date) &gt;&amp; /tmp/log/make.test.20150122-Thu-0834 &amp;
  % echo !-1:30
  /tmp/log/make.test.20150122-Thu-0834
  </code></pre>
  <p>The example above works, but you have to count and know that the word you want is the 30th word, which is time-consuming and error-prone.</p>
  <p>Is there an easy way to get the second-to-last (penultimate) word?</p>
  <p>UPDATE:
  Note that I'm looking for something to type on the command line (e.g., a <em>history expansion</em>, like the <code>!!</code> <em>event designator</em>, or the <code>$</code> <em>word designator</em>), as opposed to using <em>readline key bindings</em> (e.g., the <kbd>esc</kbd> key).</p>
  <p>(Note that this question refers to the arguments of a previous command in an interactive shell, and not to arguments passed to a shell script from the command-line, as some answers and comments here are referring to.)</p>