Register
It is currently Sun Sep 21, 2014 12:02 am

i love an array


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Mon May 16, 2005 8:43 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 667
Location: Des Moines, Iowa
Originally posted by jbsnake

yes...you can sing that to the tune of "i love a parade"
anyway :)
i'm here to simplify arrays for everyone
all an array is, is a chest of drawers
each drawer is a variable
the bottom (or top) drawer is 0
want an example?
no prob :)
Code:
#!/bin/bash
# i want a chest of drawers (not sure how many drawers i want yet)
declare -a chest;

# drawer 1 has socks in it
chest[0]="socks"

# drawer 2 has shirts in it
chest[1]="shirts"

# drawer 3 has pants in it
chest[2]="pants"

# we get the total number of filled drawers in the chest
numberofdrawers=${#chest[*]}

# make a loop with what we know
# increasing by one each time it loops
for (( drawernumber=0; $drawernumber != $numberofdrawers; drawernumber++ ))
do
echo "${chest[$drawernumber]} are in the number $((drawernumber+1)) drawer...with actual drawer number $drawernumber"
done

if you run that i think you'll have a good understanding of arrays :)


Top
 Profile WWW  
 PostPosted: Tue Feb 06, 2007 3:15 pm   

Joined: Tue Feb 06, 2007 2:25 pm
Posts: 13
Location: Liverpewl
remember bash also supports sparse arrays.


Top
 Profile  
 PostPosted: Tue Feb 06, 2007 4:39 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
perhaps you'd like to show how those work...


Top
 Profile  
 PostPosted: Mon Aug 27, 2007 2:04 pm   

Joined: Mon Apr 24, 2006 2:39 pm
Posts: 30
Location: Villahermosa
extract from the LDP scripting guide:

Quote:
# Some members of the array can be left uninitialized.
# Gaps in the array are okay.
# In fact, arrays with sparse data ("sparse arrays")
#+ are useful in spreadsheet-processing software.


http://tldp.org/LDP/abs/html/arrays.html

Not sure I caught the samples.


Top
 Profile WWW ICQ YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP