Create a relative symbolic link when the target is specified as either an absolute path or a path relative to the directory from where the script is called.
Not 100% working.
Usage ∞
find . -name '* *' | while read i; do relative.sh -c "$i" ; done
find . -name 'File*' | while read i; do relative.sh -c "$i" ; done
Fun limitation ∞
su cd / mkdir -p /1/1/1/source_dir/ touch /1/1/1/source_dir/source_file mkdir -p /1/1/0/linked_dir/ ln -s /1/1/0/linked_dir /0 ln -s /1/1/1/source_dir/source_file /0/source_file_linked # This works: ls -al /1/1/1/source_dir/source_file /0/source_file_linked # Note: I'm making relative.sh pass through that linked directory. # This is a rather interesting problem. /tmp/relative.sh -c /0/source_file_linked # This does not! ls -al /0/source_file_linked ls -al /1/1/0/linked_dir/source_file_linked # Look at my original "ls": ls -al /1/1/1/source_dir/source_file /0/source_file_linked # You can see that "../" replaces "/0/" and ../1/1/1/source_dir/source_file looks sensible. # but cd into /0 and try to ls ../ and what do you see? # What you expect is to see your root filesystem. cd /0 ls ../ # But what you actually see are the contents of /1/1/0 (linked_dir/) # Why? Dunno. (Linux secretly hates me. Ok, maybe not so secretly.) # Solution? cd /1/1/0 ln -s /1 # Yep, that works. ls -al /0/source_file_linked # Clean up (be careful, you are root!) rm -i /0 rm -ri /1
more ∞
mkdir -p foo/bar ln -s foo/bar baz touch baz/../quux
You’ll notice the file foo/quux is created (not ./quux)
Also try doing:
stat baz stat baz/.
And you’ll notice that baz/. is not the same file as baz, because baz is a symbolic link to foo/bar and baz/. is a hardlink to foo/bar
