![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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
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
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 |
|
||||
|
I have found it by myself:
Code:
eval echo $\{#inf_ln_$a[@]\}
> 10
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| bash, bash eval, eval |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|