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.
This commit is contained in:
Avery Pennarun 2019-01-01 19:10:55 -05:00
commit 613fcb1c34
2 changed files with 7 additions and 3 deletions

View file

@ -44,7 +44,7 @@ qdirname()
) )
_dirsplit "$0" _dirsplit "$0"
REDO=$(cd "$(/bin/pwd)" && REDO=$(cd "$(pwd -P)" &&
cd "${_dirsplit_dir:-.}" && cd "${_dirsplit_dir:-.}" &&
echo "$PWD/$_dirsplit_base") echo "$PWD/$_dirsplit_base")
export REDO export REDO
@ -79,7 +79,7 @@ if [ -z "$DO_BUILT" -a "$_cmd" != "redo-whichdo" ]; then
if [ "$#" -eq 0 ] && [ "$_cmd" = "do" -o "$_cmd" = "redo" ]; then if [ "$#" -eq 0 ] && [ "$_cmd" = "do" -o "$_cmd" = "redo" ]; then
set all # only toplevel redo has a default target set all # only toplevel redo has a default target
fi fi
export DO_STARTDIR="$(/bin/pwd)" export DO_STARTDIR="$(pwd -P)"
# If starting /bin/pwd != $PWD, this will fix it. # If starting /bin/pwd != $PWD, this will fix it.
# That can happen when $PWD contains symlinks that the shell is # That can happen when $PWD contains symlinks that the shell is
# trying helpfully (but unsuccessfully) to hide from the user. # trying helpfully (but unsuccessfully) to hide from the user.
@ -218,7 +218,7 @@ _realpath()
#echo "Trying: $PWD--$path" >&2 #echo "Trying: $PWD--$path" >&2
if cd -P "$path" 2>/dev/null; then if cd -P "$path" 2>/dev/null; then
# success # success
pwd=$(/bin/pwd) pwd=$(pwd -P)
#echo " chdir ok: $pwd--$rest" >&2 #echo " chdir ok: $pwd--$rest" >&2
np=$(_normpath "${pwd%/}/$rest" "$relto") np=$(_normpath "${pwd%/}/$rest" "$relto")
if [ -n "$isabs" ]; then if [ -n "$isabs" ]; then

View file

@ -517,6 +517,10 @@ rm -f shlink
ln -s . shlink ln -s . shlink
(quiet_stderr cd -L shlink/shlink/shlink/../shlink) || fail 120 (quiet_stderr cd -L shlink/shlink/shlink/../shlink) || fail 120
(quiet_stderr cd -P shlink/shlink/shlink/../shlink) && fail 121 (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.failed ] && exit 41
[ -e shelltest.warned ] && exit 42 [ -e shelltest.warned ] && exit 42