•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,420 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,625 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 796 | Replies: 1
![]() |
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I am using an array (clmlist01). I have 61 of these and have 4 or more references to each one in a block of code that I do not want to have to hardcode 61 times. With that being said, I am creating a varible and going through a for loop to create the actual name of each array. The arrays would end up being cmlist01, cmlist02, cmlist03, etc. I don't have any problem creating the variables, but I seem to be doing something wrong in the syntax because if I use ${#cmlist01[@]} it gives me 11, but if I try to resolve the variable substituion name (listnbr), it resoves to cmlist01, but the ${#listnbr[@]} always returns 1. Is it possible to do what I am trying, or do you have to always hardcode the actual array name (instead of resoving it on the fly)? Help with the syntax please!
•
•
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation:
Rep Power: 4
Solved Threads: 50
I don't think it's possible though I'm not 100% sure.
Here is what I found in the advanced scripting link I refer to.
http://www.tldp.org/LDP/abs/html/par...ml#PARAMSUBREF
So if you ask me to guess (why it prints 1) I'll say either it's printing the length of the first element, or it's printing the number of elements in the array.
Here is what I found in the advanced scripting link I refer to.
http://www.tldp.org/LDP/abs/html/par...ml#PARAMSUBREF
•
•
•
•
Variable length / Substring removal
${#var}
String length (number of characters in $var). For an array, ${#array} is the length of the first element in the array.
Exceptions:
* ${#*} and ${#@} give the number of positional parameters.
* For an array, ${#array[*]} and ${#array[@]} give the number of elements in the array.
Last edited by thekashyap : Apr 16th, 2007 at 10:22 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the Shell Scripting Forum
- Previous Thread: Need help in Shell script
- Next Thread: Find the total lines in the file


Linear Mode