if true do nothing else do
How do I write the "do nothing" statement in the following example?
Example:
if (( "$x"="1" && "$y"="a" && "$z"="happy" ))
then
do nothing
else
command
command
fi
Example:
if (( "$x"="1" && "$y"="a" && "$z"="happy" ))
then
do nothing
else
command
command
fi
if (( "$x"="1" && "$y"="a" && "$z"="happy" )); then
:
else
command
command
fi
Another way, invert your test :
Code:
if (( "$x"!="1" || "$y"!="a" || "$z"!="happy" )) then command command fi
========================
value=$( grep -ic "benjamin" /etc/passwd ) if [ $value -eq 1 ] then echo "I found Benjamin" fi
value=$( grep -ic "benjamin" /etc/passwd ) if [ $value -ge 1 ] then if [ $value -eq 1 ] then echo "I found Benjamin" elif [ $value -eq 2 ] then echo "I found two Benjamins" else echo "There are too many Benjamins" fi fi
if [ -n $value ] then echo "variable value has a value or $value" fi
The -n
operator is for checking if a variable has a string value or not.
The-z
operator is the opposite of-n
if [[ -n $1 ]] && [[ -r $1 ]] then echo "File exists and is readable" fi
if [[ -z $1 ]] || [[ ! -r $1 ]] then echo "Either you didn't give me a value or file is unreadable" exit 2 fi
Comments
Post a Comment