From 2598a2f4ec750b00610e1bac78fa3963231ab610 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Feb 2013 13:39:26 +0000 Subject: canonicalize function for paths --- helper/string.inc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/helper/string.inc b/helper/string.inc index 1d15b26e..0a166708 100644 --- a/helper/string.inc +++ b/helper/string.inc @@ -7,3 +7,8 @@ trim() { echo -n "$var" } +# usage: CANONICALIZED_STRING=$(canonalize ) +# usage with relative path requires you to be in the correct directory. +canonicalize() { + cd -P -- "$(dirname -- "$1")" && printf '%s\n' "$(pwd -P)/$(basename -- "$1")" +} -- cgit v1.2.3-55-g7522