Register
It is currently Thu Feb 22, 2018 10:32 am

test for symbolic link?


All times are UTC


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Dec 07, 2010 12:41 am   
Sr. Member

Joined: Sun Dec 12, 2004 6:08 am
Posts: 1200
Location: Cupertino, CA
Wondering what the bash script would look like for a piece of code that did the following:

Move a directory a temporary location, like "foo" --> "foo_old"
Replace the original with a symbolic link to another directory, like "ln -s /some/path/bar foo"

Ok that's real trivial by itself, but how would you check to see if "foo" was already a symbolic link pointing to "/some/path/bar" ? And if so, remove that symbolic link (but not the contents it points to).

What I'm actually trying to accomplish is to replace a system library with a debug build of the same library, and easily switch back and forth between the two (and having it robust enough so that I don't have to worry about accidentally copying over the original llbrary, etc).


Top
 Profile  
 PostPosted: Tue Dec 07, 2010 3:04 am   
Site Admin
User avatar

Joined: Thu Apr 17, 2003 3:44 am
Posts: 12300
Location: Iowa
Code:
[[email protected] ~]$ mkdir testfoo
[[email protected] ~]$ ln -s /home/crouse/testfoo/ testbar

# TESTING the symlink
DIRLINK="/home/crouse/testbar"
if [ -L "$DIRLINK" ]
then
  echo "$DIRLINK is a symlink."
else
  echo "$DIRLINK is NOT a symlink"
fi

# TESTING THE actual dir
DIRLINK="/home/crouse/testfoo"
if [ -L "$DIRLINK" ]
then
  echo "$DIRLINK is a symlink."
else
  echo "$DIRLINK is NOT a symlink"
fi


/home/crouse/testbar is a symlink.
/home/crouse/testfoo is NOT a symlink


You could check the exit status of the test with $? and it returns a 1 or 0 .... and do "whatever" based on that test.
Hope that helps.

_________________

Zbook (Laptop)- Mint 18 64-bit - I7-4800mq - 32GB ram
Phantom (Desktop)- Mint 64-bit - i7-5770 - 32GB ram
Nas4Free (NAS) - 6X3TB File Server.
Sky (HP BladeCenter) - 16 blades - 536 GB ram-G7/G6/G5 blades.


Top
 Profile WWW  
 PostPosted: Tue Dec 07, 2010 7:22 am   
Sr. Member

Joined: Sun Dec 12, 2004 6:08 am
Posts: 1200
Location: Cupertino, CA
ah, thanks.

I knew about "-e" and "-d" but never seen "-L" before.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


Powered by phpBB © 2012 phpBB Group
© 2003 - 2012 USA LINUX USERS GROUP