bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash symlink not followed as expected.


From: Bob Proulx
Subject: Re: Bash symlink not followed as expected.
Date: Thu, 21 Oct 2010 17:20:32 -0600
User-agent: Mutt/1.5.20 (2009-06-14)

Thomas Shaw - Oracle Corp wrote:
> Not sure if this is a bug but logging anyway just in case.

Thank you for the report.  However what you are describing is expected
behavior.  It isn't a bug.  It is just the way that symbolic links work.

> Symlink path is not followed as expected.  For example:

Bash and other shells that know about symlinks (optionally) handle
them by keeping track of a logical path in the PWD environment
variable.  This is a logical path and not the actual physical path.

> bash-3.00# pwd
> /ee/oce
> bash-3.00# ls -l oracle
> lrwxrwxrwx   1 oracle   oinstall       6 Oct 12 12:03 oracle -> ../oce

You have created an alias where a single path may be referred to by
multiple different names.  You have also created a loop.

> bash-3.00# cd oracle
> bash-3.00# pwd
> /ee/oce/oracle

Bash followed "how you got there" so that 'cd ..' will work to get you
back to where you were when you went into it.  The 'pwd' is a shell
builtin and returns this logical path.  Use 'pwd -P' to get the
physical path.

> bash-3.00# cd oracle
> bash-3.00# pwd
> /ee/oce/oracle/oracle

And so on.  But 'cd ..' will take you back to the last place that you
were when you went in.

> bash-3.00# pwd
> /ee/oce/oracle/oracle/oracle/oracle
> bash-3.00# sh
> # pwd
> /export/home/database/11g/oce

Your 'sh' is looking at the physical path, not the logical path.  The
physical path is the canonical location.

> # cd /ee/oce
> # ls -l oracle
> lrwxrwxrwx   1 oracle   oinstall       6 Oct 12 12:03 oracle -> ../oce
> # cd oracle
> # pwd
> /export/home/database/11g/oce
> # cd oracle
> # pwd
> /export/home/database/11g/oce

That 'sh' is using physical paths.

>    * A fix for the bug if you have one!

What you are describing is the way it is supposed to work.  Symbolic
links were developed in BSD and a wonderful invention they have proved
to be.  But they are not entirely consistent throughout.  They do not
change the behavior of the filesystem.  They are simply a symbolic
name translation for that individual target.

The logical path used to get to someplace isn't canonical.  There may
be multiple logical paths that point to a location.  You can only
cache the logical value.  If the physical path changes out from under
the cached value then they will be out of sync and there isn't any way
to avoid it.

This is a user configurable setting.  If you want canonical paths that
are always correct you should use physical paths.  The ~/.bashrc file
would be an appropriate place to place that setting.

  set -o physical

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]