I wnat to do something like:
if [[ git status &> /dev/null ]]; then
echo "is a git repo";
else
echo "is not a git repo";
fi
except I don't know how to do checking on the exit status. How do I fix this?
Thanks
I wnat to do something like:
if [[ git status &> /dev/null ]]; then
echo "is a git repo";
else
echo "is not a git repo";
fi
except I don't know how to do checking on the exit status. How do I fix this?
Thanks
Use $?
, it contains the last commands return code
EDIT: precise example:
git status >& /dev/null
if [ $? -eq 0 ]; then
echo "is a git repo"
else
echo "is not a git repo"
fi
Simply like that
if git status &> /dev/null
then
echo "is a git repo";
else
echo "is not a git repo";
fi
Or in a more compact form:
git status &> /dev/null && echo "is a git repo" || echo "is not a git repo"