Example:
absolute="/foo/bar"
current="/foo/baz/foo"
# Magic
relative="../../bar"
How do I create the magic (hopefully not too complicated code...)?
Using realpath from GNU coreutils 8.23 is the simplest, I think:
$ realpath --relative-to="$file1" "$file2"
For example:
$ realpath --relative-to=/usr/bin/nmap /tmp/testing
../../../tmp/testing