Simple script

I have a script that will check for integer line by line and if it encounter any blank space will echo it:

Below the script:


#!/bin/ksh
while read i
do
echo "Value is $i"

count=`expr substr "$i" 1 3`
echo $count

if [ $count == 000 ] && [ "$i" != " " ]
then
echo "Matched"
else
echo "Blank Space Found"
fi

done < a2.txt

contents of a2.txt

----------------------------

having provlem when the script encounter the blank line in a2.txt.
Below the output:

If a line begins or ends with a space, that read command will strip it, and it will not be part of $i.

To capture leading and trailing spaces, set IFS to en empty string:

while IFS= read i

In a POSIX shell, there is no need to use expr

temp=${i#???}
count=${i%"$temp"}

[indent]
The == operator is not standard; use =

The second test in unnecessary. If $count is 000, it cannot also be a space.

Better still, use a case statement:

case $i in
     000*) count=000;
esac

then
echo "Matched"
else
echo "Blank Space Found"
fi

done < a2.txt

contents of a2.txt

----------------------------

having provlem when the script encounter the blank line in a2.txt.
Below the output:

Value is 0001650111
000
Matched
Value is

./a9.sh[9]: test: argument expected
Blank Space Found Value is 0001650111 000 Matched Value is ./a9.sh[9]: test: argument expected Blank Space Found 

[/quote]

still having the same problem not reading blank line.....below the script


#!/bin/ksh
while IFS= read i
do
echo "Value is $i"

#count=`expr substr "$i" 1 3`
#echo $count

temp=${i#???}
count=${i%"$temp"}
echo "$count"
if [ "$count" = "   " ]
then
echo "Blank Space Found"
else
echo "Value found"
fi


done < a2.txt

output:

You haven't tested for a blank line. You have tested for a line beginning with 3 spaces.