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

Re: Subscripting without temporaries



On 2004-04-13 at 12:40 -0400, Lloyd Zusman wrote:
> > txt="Some text [particular text] Another text"
> > print -l $txt[1,$txt[(i)\[]-2] $txt[(r)\[,(R)\]] $txt[$txt[(I)\]]+2,-1]
> 
> This is cool.  But what options are necessary in order to make this
> work?  The commands above produce this output for me:
> 
>   Some
>   text
>   [particular
>   text]
>   Another
>   text
> 
> This is the same as what I get with this:
> 
>   print -l $txt

That means that you have SH_WORD_SPLIT turned on, which is not a zsh
default.

If turning sh_word_split off is not an option, then use the '='
parameter expansion modifier twice:

 print -l $==txt[1,$txt[(i)\[]-2] $==txt[(r)\[,(R)\]] $==txt[$txt[(I)\]]+2,-1]

-Phil



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