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?
For example, say I have the two following directories:
/var/data/1/
and /var/data/2/
I have a link to one of them, say, data_link
and it is currently linked to /var/data/1/
When the script is triggered, I want it to swap the link to /var/data/2/
(i.e. ln -s /var/data/2/ /somepath/data_link
).
When the script is triggered again, the opposite will happen (i.e. ln -s /var/data/1/ /somepath/data_link
), and so on. What's the easiest way to do this via a Bash script?