The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing single elements of a awk array in END timj123 Shell Programming and Scripting 6 06-20-2008 04:53 PM
Rearrange array elements-Pls help tj23 Shell Programming and Scripting 4 06-20-2008 09:29 AM
how to get status array for the commands in eval pankai Shell Programming and Scripting 2 01-10-2008 10:26 PM
To return the elements of array Sudhakar333 Shell Programming and Scripting 5 08-06-2007 02:20 PM
Confuse on how to use array and eval.. Kinki UNIX for Dummies Questions & Answers 2 02-14-2005 06:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-01-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
eval, array, number of elements - couldn't get it

I try to get a number of elements in an array, using dynamic array name.
I need the array name to be dynamic.

The array name is constructed as 'inf_ln_$nmb', where $nmb is a file line number
So, say I have the arr 'inf_ln_4':
Code:
> for (( el=0; el<${#inf_ln_4[*]}; el++ )); do 
>    echo "$el: >"${inf_ln_4[$el]}"<"; 
> done
0: >Address 2<
1: >Memphis, TN 38134<
2: ><
3: >31<
4: >11/1/2003<
5: >6/30/2004<
6: >00018906465 MAC 01<
7: >TRUE<
8: ><
9: ><
> # or :
>  echo ${inf_ln_4[@]}
Address 2 Memphis, TN 38134 31 11/1/2003 6/30/2004 00018906465 MAC 01 TRUE
I do next:
Code:
>
>a=4;  # this is to be used for dynamic array's name 
> eval echo ${inf_ln_$a[@]}     # expect 'eval' will replace $a for  4
bash: ${inf_ln_$a[@]}: bad substitution
>
> # the same I have by trying to access an array element:
> eval ec ${inf_ln_$a[0]}
bash: ${inf_ln_$a[0]}: bad substitution
Is there a way to prevent the bash-shell from treat the '$a[0]' as a substitution?

My main attempt is to copy the current dynamicaly numbered array to some staticly-named array to comfortably work with it's element

Appreciate your advise or help!
Alex
  #2 (permalink)  
Old 07-01-2008
alex_5161 alex_5161 is offline
Registered User
  
 

Join Date: Jan 2007
Location: Detroit
Posts: 124
I have found it by myself:
Code:
 eval echo $\{#inf_ln_$a[@]\}
> 10
Sponsored Links
Closed Thread

Bookmarks

Tags
bash, bash eval, eval

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0