0

I have a script named temp.sh. I am running it from another script like...

sh temp.sh | tr '|' '\n' > sel-employee
count=`wc -l sel-employee`

if [ '$count' == 0 ] ; then 
echo "ERROR"
else
echo "SUCCESS"
fi

when I run this script if file sel-employee has zero line OR more then zero line in both cases it is output SUCCESS. I can not understand why?

0

1 Answer 1

3
if [ '$count' == 0 ] ; then 

The variable count isn't expanded because it's in single quotes. Use double-quotes: "$count". The string $count is different from the string 0, so the comparison is always false. Run the script with sh -x to see the commands that shell runs. Also, you should use =, not ==, the latter is not standard and doesn't work in all shells.

Not the answer you're looking for? Browse other questions tagged .