views:

11

answers:

1
#!/bin/sh
cat PLAYARTE_TXT.txt|while read line
do
count1=$(echo $line|wc -c)
a=37
if [[ $count1 -eq  $a ]];
then
b=0 
else
c=1
break
fi
done
if [ "$b" -eq "0" -a "$c" -ne "1" ];
then
echo success
else
echo failure
fi
exit 0
+1  A: 

cat is redundant and is the cause to your problem because the "|" pipe creates a subshell. That's why when you go out of the while loop, the value of $b is "lost". just redirect the file to while read loop

#!/bin/bash
while read -r line
do
 count1=$(echo "$line"|wc -c)
 a=37
 if [ "$count1" -eq  "$a" ];then
   b=0
 else
   c=1
   break
 fi
done  < "PLAYARTE_TXT.txt"
if [[ "$b" = 0 && "$c" != 1 ]];then
 echo success
else
 echo failure
fi
exit 0
ghostdog74
Thank you very much but how do i specify the file where it has to read
what do you mean? the file is redirected. see my code again. Otherwise, if you are talking about passing the file name to the script, you can use `$1` (or `$@`)
ghostdog74