Fixing grep compatibility on older systems

Unfortunately, older versions of grep don't have `-m` or `-q`.
Wherever `-q` was being used silence output, I changed it to redirect to `/dev/null`.
Wherever `-m1` was used to stop searching after the first match, I replaced it with `-l`.
Wherever `-m1` was used to only take the first line of output, I piped it into `head -n1`.

This fixed compatibility for me with grep on Solaris 9.