maillog: 12/01/2005-03:11:15(-0800): Jeremy Huddleston types > Ok, I'm sure someone has some code for this lying around, so I really > don't want to reinvent the wheel when I've got so much else to do... > so... > > Does anyone know a way to find the relative path between two absolute > paths... for instance, I want something which behaves like: > > # find_relative_path /usr/include/asm-sparc /usr/include/asm > ../asm-sparc > > If it's a bash function, that would be great, but relying on things in > 'emerge system' would be alright.
Google only turns up complex pieces of software (there was even a freeware for windows), so here is a piece of bashery that does the trick. - If you are always going to use real directories, or if you want to use real paths (dereferenced symlinks), you may want to (cd $dir && /bin/pwd) for $src and $dst. - Having '../' or './' in a parameter will break the output, but "dirname" is not too smart about those either, so who cares. - First parameter is assumed to be a directory (in case you want to ever pass a file -- use `dirname`). - Second parameter may be a file -- it doesn't really matter where the resulting path will point to. -- \ Georgi Georgiev \ <SpanKY> i just so happen to have \ / [EMAIL PROTECTED] / /usr/portage/distfiles mounted on a fat / \ +81(90)6266-1163 \ driver <seemant> how fat is the driver? \
rel.sh
Description: Bourne shell script
pgp2m4PtkH7UR.pgp
Description: PGP signature
