Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: bug
On Dec 20, 6:08pm, Ray Andrews wrote:
}
} function z
} {
} var=$1
} echo "var:/${1:0:1}/${1:1:1}/${1:2:1}/"
} echo "var:/${var:0:1}/${var:1:1}/${var:2:1}/"
}
} }
}
} $ z abcde
}
} var: /a/a/b/
} var: /a/b/c/
}
} How can that be correct?
I'm still not sure it's correct, but this explains why it happens:
For further compatibility with other shells there is a special case
for array offset 0. This usually accesses to the first element of
the array. However, if the substitution refers the positional
parameter array, e.g. $@ or $*, then offset 0 instead refers to
$0, offset 1 refers to $1, and so on. In other words, the
positional parameter array is effectively extended by prepending
$0. Hence ${*:0:1} substitutes $0 and ${*:1:1} substitutes $1.
So :0:1 is acting on the invisible $0 even though the reference is to
an individual positional parameter rather than to the positional array.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author