-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using 'readlink -f' instead of 'realpath'. Added pure shell function to get relative path between two dirs. Set LC_ALL only for Linux. Echo 'uname' on 'make test'
- Loading branch information
Showing
4 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
# | ||
# from: https://unix.stackexchange.com/questions/573047/how-to-get-the-relative-path-between-two-directories | ||
# | ||
# Expects two parameters, source-dir and target-dir, both absolute canonicalized | ||
# non-empty pathnames, either may be /-ended, neither need exist. | ||
# Returns result in shell variable $REPLY as a relative path from source-dir | ||
# to target-dir without trailing /, . if void. | ||
# | ||
# Algorithm is from a 2005 comp.unix.shell posting which has now ascended to | ||
# archive.org. | ||
|
||
pnrelpath() { | ||
set -- "${1%/}/" "${2%/}/" '' ## '/'-end to avoid mismatch | ||
while [ "$1" ] && [ "$2" = "${2#"$1"}" ] ## reduce $1 to shared path | ||
do set -- "${1%/?*/}/" "$2" "../$3" ## source/.. target ../relpath | ||
done | ||
REPLY="${3}${2#"$1"}" ## build result | ||
# unless root chomp trailing '/', replace '' with '.' | ||
[ "${REPLY#/}" ] && REPLY="${REPLY%/}" || REPLY="${REPLY:-.}" | ||
} | ||
|
||
pnrelpath "$1" "$2" | ||
|
||
echo $REPLY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters