bc is a command line calculator for *nix. Did you know that you can script with it?


sum = 0

while(1) {
number = read()
if(number == 0) break;
sum += number
}

print sum

You can then invoke your script as follows:


bc <bc script filename> < <data filename>

or

cat <data filename> | bc <bc script filename>



Related Leave a Comment