From 613fcb1c342de9e9d140fcdf46ee2123467d3561 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 1 Jan 2019 19:10:55 -0500 Subject: [PATCH] minimal/do: use 'pwd -P' instead of '/bin/pwd'. On MacOS (at least 10.11.6), /bin/pwd defaults to using $PWD (ie. pwd -L). On most other OSes it defaults to *not* using $PWD (ie. pwd -P). We need the latter behaviour. It appears that 'pwd -P' has been specified by POSIX for quite a few years now, so let's rely on it. shelltest.od will now also check for it, though if your 'sh' doesn't support this feature, it'll be too late, because shelltest needs minimal/do in order to run. --- minimal/do | 6 +++--- t/shelltest.od | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/minimal/do b/minimal/do index e103c97..9c25919 100755 --- a/minimal/do +++ b/minimal/do @@ -44,7 +44,7 @@ qdirname() ) _dirsplit "$0" -REDO=$(cd "$(/bin/pwd)" && +REDO=$(cd "$(pwd -P)" && cd "${_dirsplit_dir:-.}" && echo "$PWD/$_dirsplit_base") export REDO @@ -79,7 +79,7 @@ if [ -z "$DO_BUILT" -a "$_cmd" != "redo-whichdo" ]; then if [ "$#" -eq 0 ] && [ "$_cmd" = "do" -o "$_cmd" = "redo" ]; then set all # only toplevel redo has a default target fi - export DO_STARTDIR="$(/bin/pwd)" + export DO_STARTDIR="$(pwd -P)" # If starting /bin/pwd != $PWD, this will fix it. # That can happen when $PWD contains symlinks that the shell is # trying helpfully (but unsuccessfully) to hide from the user. @@ -218,7 +218,7 @@ _realpath() #echo "Trying: $PWD--$path" >&2 if cd -P "$path" 2>/dev/null; then # success - pwd=$(/bin/pwd) + pwd=$(pwd -P) #echo " chdir ok: $pwd--$rest" >&2 np=$(_normpath "${pwd%/}/$rest" "$relto") if [ -n "$isabs" ]; then diff --git a/t/shelltest.od b/t/shelltest.od index 6a7ecd2..ff64b51 100644 --- a/t/shelltest.od +++ b/t/shelltest.od @@ -517,6 +517,10 @@ rm -f shlink ln -s . shlink (quiet_stderr cd -L shlink/shlink/shlink/../shlink) || fail 120 (quiet_stderr cd -P shlink/shlink/shlink/../shlink) && fail 121 +x1=$(cd shlink && basename "$(pwd -P)") +x2=$(cd shlink && basename "$(pwd -L)") +[ "$x1" = "t" ] || fail 122 +[ "$x2" = "shlink" ] || fail 123 [ -e shelltest.failed ] && exit 41 [ -e shelltest.warned ] && exit 42