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
2
  • 1
    It seems that your problem is the variable palavra scope. This question might help you. Commented Mar 20, 2013 at 1:35
  • thanks had no ideia about this Commented Mar 20, 2013 at 1:37

1 Answer 1

0

Try

palavras = echo $($palavras + $(echo $linha | wc -w) | bc)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.