Inconsistent Symlinks
Set up directories as follows:
drwxr-xr-x 2 jtauber staff 68 Mar 18 17:57 A drwxr-xr-x 3 jtauber staff 102 Mar 18 17:58 B lrwxr-xr-x 1 jtauber staff 3 Mar 18 17:58 C -> B/C
Now cd into B
jtmbp:TEST jtauber$ cd B
If you try to "execute" A from here, it tells you it's a directory
jtmbp:B jtauber$ ../A -bash: ../A: is a directory
Now go back to the top directory
jtmbp:B jtauber$ cd ..
and cd into C (the symlinked directory)
jtmbp:TEST jtauber$ cd C
If you try to execute A from here, it can't find it via "../A" only "../../A"
jtmbp:C jtauber$ ../A -bash: ../A: No such file or directory jtmbp:C jtauber$ ../../A -bash: ../../A: is a directory
so the attempt at execution is based on the actual absolute path, not the path based on following the symlink.
However,
jtmbp:C jtauber$ cd ../A jtmbp:A jtauber$
So cd uses the path based on following the symlink but relative paths for execution do not.
I realise this is likely because cd is shell-based (and so knows the path that was followed to get to the current directory) whereas execution is a system call (which doesn't know the path that was followed to get to the current directory) but it's interesting nevertheless (and occasionally annoying).
This is on OS X but the behaviour is the same on Linux as far as I know.
Comments (9)
hans on March 19, 2008:
This caused me some troubles in the past.
hans on March 19, 2008:
This caused me some troubles in the past.
hans on March 19, 2008:
This caused me some troubles in the past.
I am not hans on March 19, 2008:
I am not hans on March 19, 2008:
Edward O'Connor on March 21, 2008:
(Sorry I haven't replied to your most recent email, btw; have been very swamped.)
ycngkrfac on Aug. 20, 2008:
zhtloq on Aug. 21, 2008:
Add a Comment
Last Modified: March 18, 2008
Author: jtauber
sapphirecat on March 18, 2008:
If the shell were to do more work, it could probably make the execution happen, but down that way lies madness. Any program that tried to find itself via argv[0] would then be pointed into the wrong directory.