Created
November 17, 2015 01:37
-
-
Save mem/e1184cbf7e78f5debf5f to your computer and use it in GitHub Desktop.
Next command wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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