LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Closed Thread
 
Search this Thread
Old 03-04-2004, 09:20 AM   #1
Tengil
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Rep: Reputation: 0
Unhappy 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
 
Old 03-04-2004, 11:13 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
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?
 
Old 03-04-2004, 11:30 AM   #3
Tengil
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Original Poster
Rep: Reputation: 0
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..

Last edited by Tengil; 03-04-2004 at 12:46 PM.
 
Old 03-04-2004, 12:38 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,017
Blog Entries: 54

Rep: Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764
Plz help.. schoolwork need to be done by tomorrow
Please read the LQ rules: don't ask us to do your homework.
 
Old 03-04-2004, 12:55 PM   #5
Tengil
LQ Newbie
 
Registered: Mar 2004
Posts: 11

Original Poster
Rep: Reputation: 0
Ooops so sorry... didn't know that.. but now I do
 
Old 03-04-2004, 12:59 PM   #6
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,174
Blog Entries: 4

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
And now you do.

Thread closed.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic bash script question kevpatts Linux - Newbie 3 10-12-2005 01:02 PM
Basic Bash script help valadamir Programming 2 12-01-2004 10:37 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
Basic BASH script, what's wrong??? Satriani Linux - General 2 06-02-2003 05:34 PM
help with basic syntax in bash script Supp0rtLinux Linux - Software 4 03-27-2003 06:57 PM


All times are GMT -5. The time now is 03:35 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration