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

Re: Subscripting without temporaries



On Apr 13, 12:40pm, 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

unsetopt shwordsplit

or place each of the $txt[...] in double quotes:

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

You'll find that many examples posted to zsh-users assume that arrays are
superior to strings-automatically-split-at-spaces, and therefore assume
that you're using the default zsh setting of no_shwordsplit.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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