Add "not" to if statement in shell script
- by John Crawford
I have the following script that should exist if the user does not exist.
#check if user currently exists on system
if id $User > /dev/null 2>&1
then
#user exists no need to exit program
echo "blah blah, what a waste of space"
else
echo "This user does NOT exists. Please create that user before using this script.\n"
exit
fi
My problem is that I would ideally like to place a "not" if that first if statement so that I can trim down my if, else statement. Ideally I would like something like this:
if !(id $User > /dev/null 2>&1)
then
echo "This user does NOT exists. Please create that user before using this script.\n"
exit
fi