Convert absolute path into relative path given a current directory using Bash

Example:

absolute="/foo/bar"
current="/foo/baz/foo"

# Magic

relative="../../bar"

How do I create the magic (hopefully not too complicated code…)?

24 Answers
24

Leave a Comment