Skip to content

Instantly share code, notes, and snippets.

@cls cls/next.sh
Last active May 27, 2016

Embed
What would you like to do?
Script to execute the next binary along in $PATH
#!/bin/sh
dir=${1%/*}
bin=${1##*/}
shift
unset flag
set -f
IFS=:
for d in $PATH; do
if [ "X$d" = "X$dir" ]; then
flag=1
elif [ -n "$flag" ] && [ -x "$d/$bin" ]; then
exec "$d/$bin" "$@"
fi
done
printf "%s: no \`%s' found beyond \`%s' in \$PATH\n" "${0##*/}" "$bin" "$dir" >&2
exit 127
@cls

This comment has been minimized.

Copy link
Owner Author

cls commented Apr 6, 2015

Example usage:

$ cat ~/bin/ls
#!/bin/sh
exec next "$0" -1 "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.