1

well im in this for hours and I can't understand why I cant save the values to the variable:

let inicio=${tlinhas[0]}/2+1
tail -n +$inicio $1 | head -n $tlinhas | grep $2 | while read linha
do
    let palavras=$palavras+$(echo $linha | wc -w)
    echo $palavras 
done
printf "%d" $palavras

the problem is that every time I print the variable palavras its always zero but if I print it inside the while it has the value 14

 [leganuno@LegaNuno-PC FichasIndividuais]$ ./exercicio1.sh f1 Licenciatura
 7
 7
 0
Nuno Barros
  • 101
  • 2
  • 11

1 Answers1

0

Try

palavras = echo $($palavras + $(echo $linha | wc -w) | bc)
Lurk21
  • 2,307
  • 12
  • 37
  • 55