# find next entry in PATH for wrapper scripts # Usage: next-in-path 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 }