#!/bin/bash -eu # Function to find the next executable in the path find_next_in_path() { # Get the path to the current command local prog_path="${1:-${BASH_SOURCE[1]}}" local cmd="$(basename "$prog_path")" local dir="$(dirname "$prog_path")" # Initialize found flag to false local found=false local return_next=false # Loop through the directories in PATH IFS=':' for path in $PATH; do # Check if the current path is in the current directory if [ "$dir" = "$path" ]; then return_next=true elif [ "$return_next" = true -a -e "$path/$cmd" ]; then echo "$path/$cmd" found=true break fi done if [ "$found" = false ]; then echo "Command not found in any parent directory of PATH." return 1 fi return 0 } if [ "$0" = "$BASH_SOURCE" ]; then find_next_in_path "$@" fi