shell: remove extraneous/conflicting function

The 'whence' function defined in /etc/profile serves a limited purpose
with Bash as the default shell. Bash already provides
which/type/command as built-ins, which the function simply wraps.

Additionally, zsh has a built-in 'whence' command, which is masked by
the definition in /etc/profile. The function does not work under zsh,
breaking core zsh functionality as a result.

Fixes #18612

Change-Id: Ia34d95ffd58b2cb06d71145a217a9017657fa4a3
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6979
Reviewed-by: Adrien Destugues <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Zach Dykstra
2023-10-04 16:53:30 +00:00
committed by Adrien Destugues
parent 006478bfce
commit 26d22ee8dc
-71
View File
@@ -33,75 +33,6 @@ alias m="more"
test -n "$BASH_VERSION" && shopt -s checkwinsize
#
# and now we include a few useful things...
#
#
# An almost-ksh compatible `whence' command. This is as hairy as it is
# because of the desire to exactly mimic ksh.
#
# This depends somewhat on knowing the format of the output of the bash
# `builtin type' command.
#
# Chet Ramey
# [email protected]
#
test -n "$KSH_VERSION" || whence()
{
local vflag= path=
if [ "$#" = "0" ] ; then
echo "whence: argument expected"
return 1
fi
case "$1" in
-v) vflag=1
shift 1
;;
-*) echo "whence: bad option: $1"
return 1
;;
*) ;;
esac
if [ "$#" = "0" ] ; then
echo "whence: bad argument count"
return 1
fi
returnValue=0
for cmd
do
if [ "$vflag" ] ; then
echo $(builtin type $cmd | sed 1q)
else
path=$(builtin type -path $cmd)
if [ "$path" ] ; then
echo $path
else
case "$cmd" in
*/*) if [ -x "$cmd" ]; then
echo "$cmd"
else
returnValue=1
fi
;;
*) case "$(builtin type -type $cmd)" in
"") returnValue=1
;;
*) echo "$cmd"
;;
esac
;;
esac
fi
fi
done
return $returnValue
}
if test -n "$KSH_VERSION"; then
ps1_pwd() {
local e=$? d=${PWD:-?}/ p=~
@@ -110,11 +41,9 @@ if test -n "$KSH_VERSION"; then
return $e
}
PS1=${PS1/'\w'/'$(ps1_pwd)'}
alias which='whence -p'
else
test -n "$BASH_VERSION" || PS1=$(printf '%s' "$PS1" | \
sed 's/\\w/$PWD/')
alias which='whence'
fi
function dir {