Begginers problem - arbitary numbers
Howdy. :) I am very new to Linux and am having some some difficulty with a paritcular problem. I am trying to write a script that reads in ten arbitary numbers and prints to the screen the sum of these numbers. Anyone have any ideas how I would go about doing this?
|
Haven't tried it but I guess (assuming the arbitary number is a random number from /dev/random) then:
#!/bin/bash until [ $i -eq 10 ] do $i = /dev/random $sum = $sum + $i done echo "The total is: $sum" if you get an error, its probably my syntax is wonky with the brackets, have a quick squint at the bash/while/until manpage or the likes or on google to debug. Cheers, Ali Ross |
Code:
#!/bin/bash Moreover, you should initialize the variables, for safety. This should work: Code:
#!/bin/bash instead of Code:
i=$RANDOM Code:
read i |
All times are GMT -5. The time now is 04:42 PM. |