title: Bash Script: copy directory to external drive - how to navigate directories?
body: <p>I have JUST started looking into the world of scripting, specifically with with bash, and am trying to write a simple script to copy the contents of a folder (that contains sub-folders) to a back-up location on an external flash drive (trying to back-up Thunderbird's data).  I've looked at a couple of tutorials and what I'm running into are issues with how to navigate to parent directories within the script. The folder I want to copy exists in the directory 1 above where my script file lies.  To get to the hard drive I've got to back-up through two parent directories...  Here's what I've created (I'm running ubuntu 12.04):</p>
  
  <pre><code>#! /bin/bash
  
  #this attepmts to copy the profile folder for Thunderbird to the backup drive
  echo "...attempting to copy Thunderbird Profile to back-up drive (My Passport)"
  
  #attempt to backup two directories to where media folder (and therefore My Passport is located)
  parent=$(dirname $PWD)
  grandparent=$(dirname $parent)
  greatgrand=$(dirname $grandparent)
  
  #show what directories the variables are set to
  echo "...parent: $parent"
  echo "...grandparent: $grandparent"
  echo "...greatgrand: $greatgrand"
  
  echo "...copying..."
  
  #FIRST SUBSHELL 
  #create a subshell and cd to directory to copy &amp;&amp; tar directory
  #tar: -c = create tarball, -f = tells it what to create " - " = is the unix convention for stdout (this goes with the -f) " . " = means the whole directory.  I the end this first subshell is creating a tarball and dumping it in stdout
  # | = pipe
  #SECOND SUBSHELL
  
  (cd /mcp/.thunderbird/lOdhn9gd.default &amp;&amp; tar -cf - .) | (cd $greatgrand/media/My Passport/Gmail_to_Thunderbird_Backup &amp;&amp; tar -xpf -)
  </code></pre>
  
  <p>When I run this I get:</p>
  
  <pre><code>mcp@mcp-Satellite-A135:~/BashScriptPractice$ ./thunderProfileBU.sh
  ...attempting to copy Thunderbird Profile to back-up drive (My Passport)
  ...parent: /home/mcp
  ...grandparent: /home
  ...greatgrand: /
  ...copying...
  ./thunderProfileBU.sh: line 23: cd: //media/My: No such file or directory
  ./thunderProfileBU.sh: line 23: cd: /mcp/.thunderbird/lOdhn9gd.default: No such file or directory
  </code></pre>
  
  <p>I should be starting in the directory "/mcp".  I'm guessing I don't need it in the first sub-script (the last line) above but when I tried to just use "cd /.thunderbird/lOdhn9g..." I was still getting the error.  For the second sub-script I'm not sure exactly what is happening.  Am I just misunderstanding the folder navigation syntax?</p>
  
  <p>Also, this is a side question but is scripting in this manner something a software developer should know how to do or is this kind of thing more reserved for system admins?  I haven't taken any scripting classes or do I know of any offered through my university however I find it interesting and can see how it could be pretty useful...  Thanks!</p>