[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Remove an empty (null) element in an indexed array
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] Remove an empty (null) element in an indexed array |
Date: |
Thu, 25 Apr 2013 16:32:55 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Apr 25, 2013 at 10:22:33PM +0200, John Kearney wrote:
> but if you just want to iterate over the sparse array you can just do.
>
> for ckey in address@hidden; do
> echo "${FOO[${ckey}]}"
> done
That's the correct way if you actually need to use the index values
during the iteration (although you'd want quotes if this were an
associative array).
If you just need to iterate over the values, and don't need the indices,
then it can be simplified:
for value in "address@hidden"; do
...
done
Or you can use printf's implicit looping if all you're doing is printing
the values (I showed that earlier).