I am not quite unfamiliar with bash scripts, yet, I am faced with a rather lame problem.
I have a short bash script code that is something like this:
cat $file | while read line; do
let "total = $total + $len"
My problem is that the value of variable "total" is always zero outside the loop. I.e. the final echo command always reports 0, whilst the echo command inside the while loop reports the correct total.
Are bash variables local to the while loop in this syntax? If yes, is there a workaround, to use their values outside the loop?
The above code snippet is of course just a meaningless example to show the problem. The code would be part of a script that splits up a large text file into smaller chunks having a fixed maximum number of characters.
The "split" command has proven to be unsuitable for this purpose, as it happily breaks unicode characters in two.
Anyway, if there is an other code snipped for the purpose using bash/awk/sed, it would be welcome.