title: bash script to automate wget tar cd using word designators and word modifiers
body: <p>How can I automate the following with a bash shell script using word designators and word modifiers or something similar?</p>
  
  <pre><code>root@server:/tmp# wget -q http://download.zeromq.org/zeromq-2.2.0.tar.gz
  root@server:/tmp# tar -xzf !$:t
  tar -xzf zeromq-2.2.0.tar.gz
  root@server:/tmp# cd !$:r:r
  cd zeromq-2.2.0
  root@server:/tmp/zeromq-2.2.0#
  </code></pre>
  
  <p>When I try something like the below I get errors because word designators and word modifiers don't appear to work the same way in bash scripts as they do in a shell:</p>
  
  <p>Bash Shell Script Example 1:</p>
  
  <pre><code>#!/usr/bin/env bash
  wget -q http://download.zeromq.org/zeromq-2.2.0.tar.gz &amp;&amp; tar -xzf !$:t &amp;&amp; cd !$:r:r
  
  root@server:/tmp# ./install.sh 
  tar (child): Cannot connect to !$: resolve failed
  
  gzip: stdin: unexpected end of file
  tar: Child returned status 128
  tar: Error is not recoverable: exiting now
  </code></pre>
  
  <p>Bash Shell Script Example 2:</p>
  
  <pre><code>#!/usr/bin/env bash
  wget -q http://download.zeromq.org/zeromq-2.2.0.tar.gz
  tar -xzf !$:t
  cd !$:r:r
  
  root@server:/tmp# ./install.sh 
  tar (child): Cannot connect to !$: resolve failed
  
  gzip: stdin: unexpected end of file
  tar: Child returned status 128
  tar: Error is not recoverable: exiting now
  ./install.sh: line 11: cd: !$:r:r: No such file or directory
  </code></pre>