Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Recent Updates
[Yesterday at 11:48:22 AM]

[Yesterday at 11:48:22 AM]

[Yesterday at 11:48:22 AM]

[Yesterday at 11:48:22 AM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » Shell Script
 bash shell script accessing array variables
Pages: [1]   Go Down
  Print  
Author Topic: bash shell script accessing array variables  (Read 2404 times)
Mark David
Administrator
Super Elite Member
*****



Karma: 185
Offline Offline

Posts: 1624

!!!Techno King!!!

fabulous_designer
View Profile WWW
bash shell script accessing array variables
« Posted: March 16, 2007, 01:09:04 PM »


bash shell script accessing array variables

The bash shell allows a number of methods for accessing elements of variable arrays. This recipe demonstrates some of these techniques.

Given the array defined by the following code:

Code:
names=( Jennifer Tonya Anna Sadie Molly Millie)

The individual elements in the array can be accessed by their numeric index (remember that they start counting a zero) with:

Code:
${names[0]}  -> Jennifer 
${names[3])  -> Sadie

All of the elements can be accessed at the same time (which is useful in a for loop) with the following:

Code:
${names[@]} 
${names[*]}

The number of elements in the array can be obtained with:

Code:
${#names[@]}  -> 6

A range of elements can easily be specified with the following syntax:

Code:
${names[@]:2:3}  -> Anna Sadie Molly 
${names[@]:3}  ->  Sadie Molly Millie

The first example starts at element 2 (the third element) and returns the next three elements (:2:3). The second example starts at record 3 and returns all of the remaining records (:3).

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.088 seconds with 24 queries.