$0
is not a positional parameter, it's not part of $@
, it's the name of the script/function. $*
, $@
and $argv
are all the same normal (non-sparse) array of the positional parameters and all array indices start at 1 in zsh unless you enable the ksharrays
option.
But if you enable the ksharrays
option for array indices to start at 0, you'll notice that $argv[0]
or ${@[0]}
is the first positional parameter: $1
.
Your confusion may be coming from arrays of ksh93-like shells (including bash
), where ${@:0:1}
is $0
even though the expansion of "$@"
doesn't include $0
. That confusion is the result of Korn choosing to make its shell array indices start at 0 even though the Bourne shell which it is based on, and most other shells and tools used by the shell chose to have their array indices start at 1.
More on that at Is there a reason why the first element of a Zsh array is indexed by 1 instead of 0?
bash ./a 1 2
orsh ./a 1 2
? – Stéphane Chazelas Apr 14 '20 at 10:09./a 1 2
in a zsh environment which is the same with the case 2. I don't know why the results are different. But I found if I try toecho $-
in the script, the first is "hB" and the second is "569X", may be it's the reason. But I don't quite know why the option is so different between the two. – Tom Tsai Apr 14 '20 at 10:32/bin/zsh ./a 1 2
? OrLC_ALL=C sed -n 'l;q' < a
? – Stéphane Chazelas Apr 14 '20 at 10:34# x!/bin/zsh
or#!/bin/zsh
? – Stéphane Chazelas Apr 14 '20 at 10:44