Skip to content

Instantly share code, notes, and snippets.

@cls
Last active May 27, 2016 12:24
Show Gist options
  • Select an option

  • Save cls/546f71fad99558af48ee to your computer and use it in GitHub Desktop.

Select an option

Save cls/546f71fad99558af48ee to your computer and use it in GitHub Desktop.
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
Copy link
Copy Markdown
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