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

Re: Unexpected behavior of P parameter expansion flag inside arithmetic evaluation



On Wed, 17 Aug 2011 11:10:20 +0200
Nikolai Weibull <now@xxxxxxxx> wrote:
> % a=(abc)
> % (( r = $#a )); echo $r
> 1
> % b=a
> % (( r = ${#${(P)b}} )); echo $r
> 3
> % (( r = ${#${(P@)b}} )); echo $r
> 1
> 
> Why is the ‘@’ needed in this case?

(( ... ))

is equivalent to

let "..."

i.e. is in double-quoted context, so $b will interpolate $a as a
scalar.  See the documentation on arithmetic evaluation in the zshmisc
manual page.

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



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