UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old July 20th, 2004, 10:16 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
how do you get 10 inputs into an array ?

very simple task, but hard concept to grasp.

im supposed to grab 10 inputs / integers from the user. what i did was this:


echo "Please enter 10 scores"
read -a scores

... but when i try to echo out the array scores, it only shows the first input. i don't think other 9 inputs are recorded. what am i doing wrong?

echo $scores


...is the cmd i am using to display them. but it only shows the first input. can someone help plz?

-ivalice

Reply With Quote
  #2  
Old July 20th, 2004, 10:32 AM
razorbak razorbak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 4 razorbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
try changing your read to:

read score1 score2 score3 score4 score5 score6 score7 score8 score9 score10

echo $score1
echo $score2
echo $score3
echo $score4
echo $score5
echo $score6
echo $score7
echo $score8
echo $score9
echo $score10

Reply With Quote
  #3  
Old July 20th, 2004, 10:32 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
nevermind. i got it. i think it was jim or someone that posted this website:

http://www.tldp.org/LDP/abs/html/internal.html#EX33

it proves to be very useful.

now if someone can tell me how i can sort these numbers in descending order?
the instructor told me to use a concept called 'bubble sort', but i don't know how. i'm thinking if i can someone get those numbers into a file, and sort them with option (-d), and then bring it back into the array.

i also need help calculating the sum and the average!

Reply With Quote
  #4  
Old July 20th, 2004, 10:34 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by razorbak
try changing your read to:

read score1 score2 score3 score4 score5 score6 score7 score8 score9 score10

echo $score1
....echo $score9
echo $score10

yeah thanks.
i would of done that, but i re-read the question, and it states "at least" . which is a problem.since it has to be at least 10 inputs, but unlimited in terms of maximum.

thank you all the same. its hard to get a reply quickly here

(especially when you are on a deadline!)

-ivalice

Reply With Quote
  #5  
Old July 20th, 2004, 11:32 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
okay, for the average of the array, i am trying to use 'bc'. the built-in calculator. so far i have this:

i=0
sum=0
while [ $count -ne 0 ]
do
sum=`expr ${scores[i]} + $sum`
i=`expr $i + 1`
count=`expr $count - 1`
done

echo the sum is equal to $sum


... this will get me the sum of the numbers inputted. how can i use 'bc' so that i can find the average ? i'm not very experienced with piping, which is what i think i must do. i had something like this line:

echo `bc $sum/$count`

but it won't calculate when i try to run the script. there has to be another way.

thanks for any help!

-ivalice

Reply With Quote
  #6  
Old July 20th, 2004, 11:38 AM
ivalice ivalice is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 16 ivalice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ah! i just found it online!

echo "$sum/$tempcount" |bc


yes!

found it here:
http://www.shelldorado.com/newslett...2002-3-Aug.html

i saw another page that showed you how to do it by setting an alias, but that seemed like a little extra legwork . especially since i've been up all night doing dam scripting@!

-iliva

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > how do you get 10 inputs into an array ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway