From 9cf23ae2d4762358b83fb5671d9cc42a5819a6b9 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 3 Oct 2016 17:25:55 -0700 Subject: [PATCH] Fallback to relative path if directory doesn't exist. --- scripts/config.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/config.sh b/scripts/config.sh index 565df65a..94debdac 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -5,11 +5,16 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function relative() { local full_path="${SCRIPT_DIR}/../${1}" - # Use readlink as a fallback to readpath for cross-platform compat. - if ! command -v realpath >/dev/null 2>&1; then - echo $(readlink -f "${full_path}") + if [ -d "${full_path}" ]; then + # Use readlink as a fallback to readpath for cross-platform compat. + if ! command -v realpath >/dev/null 2>&1; then + echo $(readlink -f "${full_path}") + else + echo $(realpath "${full_path}") + fi else - echo $(realpath "${full_path}") + # when the directory doesn't exist, fallback to this. + echo "${full_path}" fi }