Well, yes and no. Specifically, no. :wink: You can prove this to yourself, if you like, by trying to subscript it. It's one of those funky special Bash things.

John ... hmmm, well I would understand it as an array, "[t]he parameters *, @ and argv are arrays containing all the positional parameters; thus `$argv[n]', etc., is equivalent to simply `$n'." (The Z Shell Manual, Parameters) ... but yes, '$@[n]' doesn't return the nth of the array, but I assume this is becuase '$n' exists for this purpose.

You know, I'd have to say that the zsh manual is simply wrong on that point (or, at best, confusing and badly written). It's somewhat nonsensical to say in this context that it's an array (broader definition) that merely can't be accessed with bash/zsh array (the proper contextual definition) syntax. (You also know by now that I love to argue. )

- John_________________I can confirm that I have received between 0 and 499 National Security Letters.

You know, I'd have to say that the zsh manual is simply wrong on that point (or, at best, confusing). It's somewhat nonsensical to say in this context that it's an array (broader definition) that merely can't be accessed with bash/zsh array (narrower contextual definition) syntax. (You also know by now that I love to argue. ;)

John ... I'd have to say your right, its confusing, nonsensical, etc, but then what would we call it? In the above 'for param in "$@"' each item in the 'thingy' is treated separately, if we replaced "$@" with "$argv" (bash/zsh) then this would return 'parameter #1 = foo bar baz', a single parameter. So, "$@" is an array, only accessed via the abbreviated $[n], its an array (of sorts) but the subscript is abstracted into an abbreviated form.

Actually, I think a technically clear explanation is possible: $@ is a parameter that expands to a list of quoted words. I still contend that $@ is not an array, regardless of whether or not its initialization source is an array, because it can't be used with shell array syntax (principally subscripting).

But, according to you, "$@" is an array because, in a for loop it expands to multiple words even when quoted, but then since "$argv" does not so expand, is argv then not an array? Seems like a reasonable conclusion to me.

- John_________________I can confirm that I have received between 0 and 499 National Security Letters.

Actually, I think a technically clear explanation is possible: $@ is a parameter that expands to a list of quoted words. I still contend that $@ is not an array, regardless of whether or not its initialization source is an array, because it can't be used with shell array syntax (principally subscripting).

John ... ok, but it isn't exactly a "parameter" is it, or rather, its no more a parameter than it is an "array". Now, a "technically clear explanation" would need to provide a name, 'x, a thingy [...]', and while I'll admit that the absence of array syntax is "confusing" I'm at a loss as to how else I might describe it. If '$n' wasn't in place, then it would make sense to '$@[n]', but far less so due to the abreviations.

John R. Graham wrote:

[...] according to you, "$@" is an array because, in a for loop it expands to multiple words even when quoted, but then since "$argv" does not so expand, is argv then not an array? Seems like a reasonable conclusion to me. :wink:

hehe ... while I didn't actually say that I'm inclined to say I'm right :) ... had I wanted, I would have provided '$argv[@]' and it would have functioned identically to "$@" in the for loop, but I used "$argv" so that it'd function as a string. How about this "resonable conclusion": I'll grant that "$@" isn't an array, if you'll grant that "$argv[@]", which behaves identically, is also not? ;)

Now you're just being silly. But then again, do we really understand what the word "silly" means in this context? Perhaps it warrants additional discussion.

John ... yes, it was silly, obviously "$argv[@]" is an array, and I wouldn't say I was "right" in the conclusions you'd drawn from my previous post, however, I was serious wrt "$@" behaving identically to "$argv[@]", and similarly with being at a loss as to how else to describe it.

Anyow, to go back a bit in the discussion, in zsh "$@" actually is an array, and elements can be accessed in the usual manner:

Code:

% cat test.zsh
!#/bin/zsh
echo "$@[2]"
% ./test.zsh foo bar baz
bar

I didn't think to check at the time, but the manual would seem to be correct ITR.

For bash '$@' only seems to functions as shorthand for '$argv[@]', with '$n' as shorthand for the elements of the (virtual/pseudo) array. So, really, my initial description can be reduced to the lack of anything more exact with which to describe it, if you want to say, no its not an array, then I'm ok with that, but I probably wouldn't think twice about describing it as such.

The description that "${@}" is an array is pretty correct: In fact, it is the only array that a POSIX shell does possess.
It is true that other bash and zsh arrays have a slgihtly different syntax, but it is obvious that this syntax was inspired by that (only) array: Actually the syntax is not that different as if this "parameter's array" would have the empty name. Syntactically it does not exactly behave like a bash or zsh array, but semantically it is without any doubt.