` Dennis Williamson wrote:
Also, it's usually not necessary to maintain an index variable
and use shift in a while loop. Use "for arg; do" which uses an implied
$@.
I tried to implement your suggestion and quickly ran into the reasons
why I did what I did.
Using the 'for x;do' format, 1 argument can't 'swallow up the next'.
This has to happen in the case of a single letter option that if
followed by it's argument -- so yeah, could set a flag and catch it
through on a another loop, but easier just to do another 'shift' and
pull the next arg.
2nd, the counter was for the non-intercepted cmdline values. The
option parser only removes options it knows about and returns the rest
to the caller -- I used the counter to index that array, w/slightly
less typing & complexity than in an earlier design I had 2 counters
- one for the input and one for the output as they would differ
as soon as some params weren't copied to the output array -- but
then went with the paradigm you saw, as it allowed me have flags that
took values, grab them, immediately, rather than setting a flag
for a next loop.
I could have used:
array_name[${array_name[*]}]="new value"...
instead of a counter, but, the counter was already there from the previous
version and less untidy looking.