It is currently Sat May 26, 2018 9:36 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: 693
Location: Des Moines, Iowa
Originally posted by jbsnake 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 :)
# i want a chest of drawers (not sure how many drawers i want yet)
declare -a chest;

# drawer 1 has socks in it

# drawer 2 has shirts in it

# drawer 3 has pants in it

# we get the total number of filled drawers in the chest

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

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

 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.

 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...

 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:

# 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.

Not sure I caught the samples.

 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: No registered users and 6 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:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group