Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 'i' subscript flag



On Apr 2,  5:37pm, Anthony Charles wrote:
}
} man zshparam says: 
} "i   Like `r', but gives the index of the match instead; this may not
} be combined with a second argument."
} 
} I just wonder why this can't be combined with another flag which would
} be useful in this case for example:
} 
} Saito% X="bar foo paz"
} Saito% print $X[(i)p*]
} 9
} Saito% print $X[(wi)p*]
} 9
} 
} but one may expect to get '3'. Is this a design choice?

In some sense, yes.  It has to do with the way that the internals of
parameter expansion were originally implemented (long before any kind
of reverse-subscripting was possible) and what it was reasonable to
layer on top of that.

Since you can always do e.g.

    % print ${${=X}[(i)p*]}
    3

it's not that significant a restriction.



Messages sorted by: Reverse Date, Date, Thread, Author