Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

posix-sh - number of elements in an array

SOLVED
Go to solution
Highlighted
Scott Williams_5
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
Sundar_7
Honored Contributor
Solution

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 ?
Scott Williams_5
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.