Negative logic in Korn shell scripts
Published on 16th October 2007 Estimated Reading Time: 1 minuteI was looking for a way to negative logic, doing something when a condition is not satisfied, that is, and found that the way to do it is to do nothing when the condition is satisfied and something when it isn't. Being used to saying do something when a condition is false, this does come as a surprise. In time, I may find another way on my UNIX shell scripting journey. Meanwhile, the code below will only create a directory when it doesn't already exist.
dirname=test
if [[ -d $dirname ]]
then
: # the colon operator means do nothing
else
mkdir test
fi