It seems wasteful to fire up another process for this (and for incrementing counters) especially if there is an input file possibly thousands of lines long, in which case this will be expensive.
Could you try:-
if [ -z "$title" -o "$title" = " " ]
then
echo "Null or space"
else
echo "Contents"
fi
If this works, fit it to your script. It might be worth adjusting the loop too to something more like this:-
#Check if values in job card are not empty
grep "TITLE:" $filename | cut -d ":" -f3 | while read title # Handle multiple records if required
do
if [ -z "$title" -o "$title" = " " ]
then
echo "10:Title Empty" ":Fail"
((itemfailed=$itemfailed+1)) # In-process
else
echo "10:Title description present." ":Pass"
((itempassed=$itempassed+1))
fi
done >> $rptfile # All output from loop appended to this file
One thing to be aware of is that the variable being read in the loop, i.e. $title will be null when you come out of the loop. You can get round this like this if you need to know the last value:-
echo "a\nb\nc" | while read val
do
echo "Read $val"
VAL=$val
done
echo "\$val is \"$val\""
echo "\$VAL is \"$VAL\""
There is no evidence the OP is using a loop. In any case, thousands of microseconds range delays shouldn't really hurt that much.
This would miss the case where title contains more than one space character, or a tab, or any combination of the above.
Beware that your echo statement is non portable, you should use instead:
printf "a\nb\nc\n" [ while read ...
Beware too that you are assuming ksh behavior by expecting VAL to be set at the end of the loop. A POSIX shell is not required to keep the VAL variable as it is set in a pipeline.