20 lines
408 B
Bash
20 lines
408 B
Bash
# find next entry in PATH for wrapper scripts
|
|
# Usage: next-in-path <program name> <current $0>
|
|
typeset -U path
|
|
next-in-path() {
|
|
local entries=( $(which -a $1) )
|
|
local index=${entries[(ie)$2]}
|
|
local result
|
|
if [[ $index -le ${#entries} ]]; then
|
|
# found $0, use next entry
|
|
result=$entries[$((index + 1))]
|
|
else
|
|
result=$entries[1]
|
|
fi
|
|
|
|
if [[ -n $result ]]; then
|
|
echo $result
|
|
else
|
|
return 1
|
|
fi
|
|
}
|