From cae7cfb01c4e39a33ef3e851851632b4f0fd5db4 Mon Sep 17 00:00:00 2001 From: Henrique Ferreiro Date: Fri, 23 Nov 2018 01:40:32 +0100 Subject: Fix SOURCEDIR, BUILDDIR and similar when `cd` prints to stdout Several variables containing directories in `aglsetup.sh` and other scripts use the common one-liner "cd $DIR && pwd -P" to resolve symlinks. Unfortunately, in some cases, `cd` writes the new directory to stdout, e.g. when using multiple search paths. This commit changes the above to "cd $DIR > /dev/null && pwd -P" to make it more robust. Change-Id: I150ecc9940d88738cf17add68290c35486a81a3b Signed-off-by: Henrique Ferreiro --- scripts/aglsetup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/aglsetup.sh') diff --git a/scripts/aglsetup.sh b/scripts/aglsetup.sh index b11a54196..e7b4b1909 100644 --- a/scripts/aglsetup.sh +++ b/scripts/aglsetup.sh @@ -27,11 +27,11 @@ # detect if this script is sourced: see http://stackoverflow.com/a/38128348/6255594 SOURCED=0 if [ -n "$ZSH_EVAL_CONTEXT" ]; then - [[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $0) && pwd -P); } + [[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $0) > /dev/null && pwd -P); } elif [ -n "$KSH_VERSION" ]; then - [[ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- ${.sh.file}) && pwd -P); } + [[ "$(cd $(dirname -- $0) > /dev/null && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) > /dev/null && pwd -P)/$(basename -- ${.sh.file})" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- ${.sh.file}) > /dev/null && pwd -P); } elif [ -n "$BASH_VERSION" ]; then - [[ $0 != "$BASH_SOURCE" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $BASH_SOURCE) && pwd -P); } + [[ $0 != "$BASH_SOURCE" ]] && { SOURCED=1; SOURCEDIR=$(cd $(dirname -- $BASH_SOURCE) > /dev/null && pwd -P); } fi if [ $SOURCED -ne 1 ]; then -- cgit 1.2.3-korg