How to check for empty string in ksh

ksh
Programmer picture Programmer · Jan 22, 2014 · Viewed 29.2k times · Source

I am writing a simple ksh script. I have to check if a string is empty or not. How to do so? This is what I have :

findRes=`find . -name believe | xargs grep -q "ser"`
if [ "${findRes:-unset}" != "unset" ];then

     print "${file}"
fi

Answer

NeronLeVelu picture NeronLeVelu · Jan 22, 2014

empty is a string without char but defined, so in this case

[ -z "${MyVar}" ]

null is the case when your action failed, not when return empty reply also, grep -q could be tested with a [ $? -ne 0 ] when search does not find the pattern