Soft link pathname conversion for Linux and Unix

John Horne john.horne at plymouth.ac.uk
Sat Apr 28 18:42:59 UTC 2007


Hi,

I have a shell problem that I am trying to easily resolve. If I have a
directory with a soft (symbolic) link in it such as:

         fred -> ../bin/csh

How can I convert the '../bin/csh' in to a full pathname? Is there a
command to do this that will work for Linux and Unices? I need it to
work for all circumstances, not just this one particular example. So
something like '../../abc/../def' should also work in being converted.

Under Linux the 'readlink -f' command works fine, but NetBSD readlink
doesn't have the '-f' option, and Solaris doesn't have readlink. I do
not want to change directory at all, so changing to the link directory
and issuing 'pwd' isn't what I want to do.

My only other thought is to process the link pathname bit-by-bit.
Preceed the pathname with the current working directory and then remove
any './' and jiggle (!) with any '../' to get the directory above. It's
messy and could get complicated. Better ideas welcome :-)



Thanks,

John.

-- 
---------------------------------------------------------------
John Horne, University of Plymouth, UK  Tel: +44 (0)1752 233914
E-mail: John.Horne at plymouth.ac.uk       Fax: +44 (0)1752 233839




More information about the users mailing list