Take the grep command, which, as you know, will succeed and add a color parameter.
grep --color "a" <<< "a"
the return code will be 0 if the option exists, otherwise it is positive.
So your bashrc will look like this:
if grep --color "a" <<<"a" &>/dev/null; then alias grep='grep --color=auto' fi
&> sends stdout and stderr to / dev / null, so if the command does not work, it is disabled. But it still returns an error code that prevents the setting of an alias.
source share