Skip to content

Commit 8783ada

Browse files
authored
[thisroot] resolve reexec sh on macos
Fixes #19965
1 parent 1274d4f commit 8783ada

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

config/thisroot.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ getTrueShellExeName() { # mklement0 https://stackoverflow.com/a/23011530/7471760
189189
# If the executable is a symlink, resolve it to its *ultimate*
190190
# target.
191191
while nextTarget=$(readlink "$trueExe"); do trueExe=$nextTarget; done
192+
193+
if [ "$(basename "$trueExe")" = "sh" ]; then
194+
# on MacOS, sh is NOT a symlink but an executable, so trueExe is 'sh' but it will
195+
# re-exec according to symlink at /private/var/select/sh, so resolve it
196+
if [ -L "/private/var/select/sh" ] && [ -e "/private/var/select/sh" ] ; then
197+
while nextTarget=$(readlink "/private/var/select/sh"); do trueExe=$nextTarget; done
198+
else
199+
# otherwise default to bash
200+
trueExe="/bin/bash"
201+
fi
202+
fi
192203
# Output the executable name only.
193204
printf '%s' "$(basename "$trueExe")"
194205
}

0 commit comments

Comments
 (0)