Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: bug
On Tue, 20 Dec 2011 19:05:11 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Dec 20, 6:08pm, Ray Andrews wrote:
> }
> } function z
> } {
> } var=$1
> } echo "var:/${1:0:1}/${1:1:1}/${1:2:1}/"
> } }
> }
> } $ z abcde
> } var: /a/a/b/
>
> 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.
Yes, it should only be doing that for array values.
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.129
diff -p -u -r1.129 subst.c
--- Src/subst.c 28 Nov 2011 09:48:22 -0000 1.129
+++ Src/subst.c 21 Dec 2011 22:31:35 -0000
@@ -2878,24 +2878,26 @@ paramsubst(LinkList l, LinkNode n, char
return NULL;
}
}
- if (horrible_offset_hack) {
- /*
- * As part of the 'orrible hoffset 'ack,
- * (what hare you? Han 'orrible hoffset 'ack,
- * sergeant major), if we are given a ksh/bash/POSIX
- * style positional parameter array which includes
- * offset 0, we use $0.
- */
- if (offset == 0 && isarr) {
- offset_hack_argzero = 1;
- } else if (offset > 0) {
- offset--;
- }
- }
if (isarr) {
- int alen = arrlen(aval), count;
+ int alen, count;
char **srcptr, **dstptr, **newarr;
+ if (horrible_offset_hack) {
+ /*
+ * As part of the 'orrible hoffset 'ack,
+ * (what hare you? Han 'orrible hoffset 'ack,
+ * sergeant major), if we are given a ksh/bash/POSIX
+ * style positional parameter array which includes
+ * offset 0, we use $0.
+ */
+ if (offset == 0) {
+ offset_hack_argzero = 1;
+ } else if (offset > 0) {
+ offset--;
+ }
+ }
+
+ alen = arrlen(aval);
if (offset < 0) {
offset += alen;
if (offset < 0)
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author