posix-sh - number of elements in an array (213 Views)
Reply
Frequent Advisor
Scott Williams_5
Posts: 40
Registered: ‎03-27-2002
Message 1 of 3 (213 Views)
Accepted Solution

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!
Honored Contributor
Sundar_7
Posts: 1,938
Registered: ‎11-07-2000
Message 2 of 3 (213 Views)

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
Scott Williams_5
Posts: 40
Registered: ‎03-27-2002
Message 3 of 3 (213 Views)

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.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.