Too many arguments

because it gives me this error if?


while read linea
     do
       #echo "Archivos Entrada: $linea"
       largo=`awk '{print length($linea)}'`
       echo "largo : $largo "

       if [ $largo == 171  ]; then  #Here's the problem, I take this line and it works
         echo "a es igual a 1"
       fi

     done <  ${PATH_DAT}/$ArchPro #while read linea


Your first problem is in

   largo=`awk '{print length($linea)}'`

$linea is not substituted because it is within 'ticks'.
And awk wants to read from stdin.
As a result $largo is empty, leading to your second problem (that should say error in [ ]).
An improvement is

   largo=`echo "$linea" | awk '{print length($0)}'`

But this can be done with a shell builtin

   largo=${#linea}
1 Like

perfect !!!!
works perfect with this was what I needed

largo=${#linea}

Actually, there's no need for a variable unless you need the length again later on:

if [ ${#linea} -eq 171  ]; then ...

Please note that integer comparison is done preferably with -eq although not needed here.

1 Like