LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trouble with a basic bash script (https://www.linuxquestions.org/questions/linux-newbie-8/trouble-with-a-basic-bash-script-153429/)

Tengil 03-04-2004 09:20 AM

Trouble with a basic bash script
 
Hi
I'm new to bash scripting in linux. I'm trying to make a script that reads numbers users write and then adds them.

This is what I've written so far..

#!/bin/bash
# A script that adds numbers

NUMBER=0
sum=0
declare -i number
echo "Enter a number"

read NUMBER

for add in *

do
if [ $NUMBER = $number ]
then
$NUMBER+=$sum
echo "Plz enter a new number, quit with a character"
read NUMBER
return
fi
#done

echo "You did not enter a number! The sum added up is $sum"
exit 0

trickykid 03-04-2004 11:13 AM

What kind of errors are you getting? Why are you declaring the values of NUMBER and sum in the script as 0's? If these are suppose to be read by the person entering them, I would think you don't need these?

Tengil 03-04-2004 11:30 AM

I'm quite new to this..

What I'm trying to do is to let a user define values that "my" script will add up. Do you have any solution to this?? Plz help..

unSpawn 03-04-2004 12:38 PM

Plz help.. schoolwork need to be done by tomorrow
Please read the LQ rules: don't ask us to do your homework.

Tengil 03-04-2004 12:55 PM

Ooops so sorry... didn't know that.. but now I do

XavierP 03-04-2004 12:59 PM

And now you do. ;)

Thread closed.


All times are GMT -5. The time now is 05:36 AM.