consider the following :
x/
ph/
file1.txt -> ./../file1.txt
file1.txt
y/
ph/ -> /x/ph/ (this is full absolute path of x/ph)
file1.txt
/y/ph
is a symlink for ph
folder in x
. and file1.txt
is a relative symlinks.
it works correctly in x
folder however if you open
/y/ph/file1.txt
instead of opening /y/file1.txt
it opens /x/file1.txt
the goal here is to have the same directory (lets say a program) in multiple places with different config files without having to have multiple copies of the program.
according to ln
's help
Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.
so relative links are relative to the actual folder's path not the current working directory. the question is : is there any workarounds for this ?
test case:
mkdir x y x/ph
echo x1 > ./x/file1.txt
echo y1 > ./y/file1.txt
ln -s $(pwd)/x/ph ./y/ph
cd ./x/ph
ln -s ./../file1.txt
cd ../..
cat ./x/ph/file1.txt
cat ./y/ph/file1.txt
expected result is x1 y1
but you get x1 x1
Edit:
to make the question clearer, run the test case in an empty folder. and try the following commands in the folder:
bor@borpc:~/tmp$ readlink -f ./x/ph/file.txt
/home/bor/tmp/x/ph/file.txt
bor@borpc:~/tmp$ readlink -f ./y/ph/file.txt
/home/bor/tmp/x/ph/file.txt
--------------^
i want that x
there to be y
. that is to make the relative symlink resolve based on pwd
(current working directory or path used to access it) rather than the actual path of the actual file.
if it is possible how would one achieve such behavior.
x
andy
names for your folders. Because there is known problem called XY problem. Could you please explain Why you want it, and also add more description what exactly do you want. In other words explain what problem are you trying to solve.