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.
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.
The original post was in the category: os_x but I'm still in the process of migrating categories over.
The original post had 4 comments I'm in the process of migrating over.