title: How to determine which directory a link is pointing to using bash
body: <p>With Bash scripting, is there a way to determine which directory a link is pointing to, then switch it to another directory based on the result?</p>
  
  <p>For example, say I have the two following directories:</p>
  
  <p><code>/var/data/1/</code> and <code>/var/data/2/</code></p>
  
  <p>I have a link to one of them, say, <code>data_link</code> and it is currently linked to <code>/var/data/1/</code></p>
  
  <p>When the script is triggered, I want it to swap the link to <code>/var/data/2/</code> (i.e. <code>ln -s /var/data/2/ /somepath/data_link</code>).</p>
  
  <p>When the script is triggered again, the opposite will happen (i.e. <code>ln -s /var/data/1/ /somepath/data_link</code>), and so on.  What's the easiest way to do this via a Bash script?</p>