LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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: Debian Testing
Posts: 19,192
Blog Entries: 4

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

Thread closed.
 
  


Closed Thread



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:58 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration