The lines in /etc/pam.d/* are spaced to line up nicely. grep and test are spacing-sensitive (or rather, insensitive to any semantics of the bytes in the strings you want to compare) -- if the strings are not exactly equal, the comparison will fail.
A quick and reasonably elegant way to normalize the spacing is to use a tool which splits on whitespace, such as Awk.
if awk -v x=1 '$1 == "#auth" && $2 == "required" &&
$3 == "pam_wheel.so" && $4 == "use_uid" {x=0}
END{exit x}' /etc/pam.d/su
then
echo "Access is not limited"
else
echo "Access is limited"
fi
or the shell itself:
while read -r auth req so opts; do
case $so:$opts in "pam_wheel.so:use_uid")
test "$auth:req" == "#auth:required" &&
echo "Access is not limited" ||
echo "Access is limited" ;;
esac
done </etc/pam.d/su
or a combination of the two (this would perhaps be the most elegant).
Alternatively, normalize all whitespace explicitly:
case $(tr -s '\t ' ' ' </etc/pam.d/su | grep -m 1 "pam_wheel.so use_uid") in
'#auth required pam_wheel.so use_uid')
echo "Access is not limited";;
*) echo "Access is limited";;
esac
(Notice also how this avoids the pesky temporary variable for the output.)
grep "pam_wheel.so use_uid" /etc/pam.d/sucommand?ifcondition where you assign (one egal sign) instead of testing egality (two egal signs)