[ale] Does anyone have a definitive way of determining the target of a soft link in bash?

James P. Kinney III jkinney at localnetsolutions.com
Tue Aug 21 11:18:09 EDT 2007


On Tue, 2007-08-21 at 11:01 -0400, Jim Lynch wrote:
> I want to flip flop two directories by pointing a soft link to one and 
> then the other the next day.  I'm trying to come up with the best way to 
> tell which of the directories is linked so I can replace the link with 
> the other one.
> 
> Something like
> 
> db1
> db2
> current -> db1
> 
> Then some sort of an if test that says
> 
> if current is linked to db1
>     ln -sf db2 current
> else
>    ln -sf db1 current
> fi
> 
> Any suggestions?

now=`ls -l current`
if { "$now" -eq "db1" }
  then
    rm current && ln -sf db2 current
  else
    if { "$now" -eq "db2"}
      then
        rm current && ln -sf db1 current
    fi
fi
new=`ls -l current`
echo "old stuff $now"
echo "new stuff $new"
> 
> Thanks,
> Jim.
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
> 
-- 
James P. Kinney III          
CEO & Director of Engineering 
Local Net Solutions,LLC        
770-493-8244                    
http://www.localnetsolutions.com

GPG ID: 829C6CA7 James P. Kinney III (M.S. Physics)
<jkinney at localnetsolutions.com>
Fingerprint = 3C9E 6366 54FC A3FE BA4D 0659 6190 ADC3 829C 6CA7
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part




More information about the Ale mailing list