which/which2.sh

20 lines
478 B
Bash
Raw Normal View History

2021-03-23 19:15:21 +00:00
# shellcheck shell=sh
# Initialization script for bash, sh, mksh and ksh
2021-04-26 12:02:33 +00:00
which_declare="declare -f"
which_opt="-f"
which_shell="$(cat /proc/$$/comm)"
2021-04-26 12:02:33 +00:00
if [ "$which_shell" = "ksh" ] || [ "$which_shell" = "mksh" ] || [ "$which_shell" = "zsh" ] ; then
which_declare="typeset -f"
which_opt=""
fi
which ()
{
2021-04-26 12:02:33 +00:00
(alias; eval ${which_declare}) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}
export which_declare
2021-04-26 12:02:33 +00:00
export ${which_opt} which