BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

posix-sh - number of elements in an array

SOLVED
Go to Solution
Highlighted
Frequent Advisor

posix-sh - number of elements in an array

Using posix shell, how do I determine how many elements are in an array.

ex:
set -A arr $(print "file1 file2 file3 file4").

I need to know that there are four elements in this array.

Thanks!
2 REPLIES
Honored Contributor

Re: posix-sh - number of elements in an array

Try this

echo "Number of elements in the array: ${#arr[*]}"


Learn What to do ,How to do and more importantly When to do ?
Frequent Advisor

Re: posix-sh - number of elements in an array

Bingo...I think I tried every variation on the placement of the "#", but couldn't get it right. Thanks for help.