POSIXly:
$ awk 'BEGIN{
n = split(ENVIRON["PATH"], p, ":")
while (n) i[p[n]]=n--
if (! (ARGV[1] in i))
print ARGV[1], "is not in $PATH"
else if (! (ARGV[2] in i))
print ARGV[2], "is not in $PATH"
else if (i[ARGV[1]] < i[ARGV[2]])
print ARGV[1], "is before", ARGV[2]
else
print ARGV[1], "is after", ARGV[2]
exit}' /bin /usr/bin
/bin is after /usr/bin
Para o seu exemplo específico:
check_order() (
test_seen=false non_test_seen=false
IFS=:; set -f
for i in $1; do
case $i in
(*test*)
if $non_test_seen; then
echo "there are some non-tests before some tests"
return
fi
test_seen=true;;
(*)
non_test_seen=true
esac
done
if $test_seen; then
echo "tests are all first"
else
echo "no tests in there"
fi
)
check_order "$LIST"