I have a file
cat <<EOF > /tmp/test
Line one
Line two
Line three
EOF
Now I am trying to get the exit stat ($?) of 1 if any text is found and 0 if any text is not found using grep, i.e. just reversing the exit status of grep
# (snippet 1) this one is not working!!! retval $? should be 1
grep -q 'one' /tmp/test && false || true
echo $?
# (snippet 2) but this one is working - retval is 1
grep -q 'one' /tmp/test
if [ $? -eq 0 ]; then
false
else
true
fi
echo $?
What am I missing in snippet 1?