Skip to content

Instantly share code, notes, and snippets.

@mem
Created November 17, 2015 01:37
Show Gist options
  • Save mem/e1184cbf7e78f5debf5f to your computer and use it in GitHub Desktop.
Save mem/e1184cbf7e78f5debf5f to your computer and use it in GitHub Desktop.
Next command wrapper
#!/bin/sh
get_next() {
IFS=:
id=$(stat -c '%D:%i' "$1")
prg=
name=$(basename "$0")
for p in $PATH ; do
n="$p/$name"
if test -e "$n" ; then
nid=$(stat -c '%D:%i' "$n")
if test "$id" != "$nid" ; then
prg="$n"
break
fi
fi
done
echo "$prg"
}
n=$(get_next "$0")
if test -n "$n" ; then
echo Calling: "$n" "$@"
exec "$n" "$@"
else
echo No next \"$(basename "$0")\" in \$PATH
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment