Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ${var:1:1:=y}
On 02/03/2015 07:25 PM, Bart Schaefer wrote:
You've forgotten that ${var=val} has the side-effect of assigning to
"var" if it is not set.
No, it was just irrelevant there.
I think what you mean is what Lawrence already
demonstrated (again several messages ahead):
variable=${${var:1:1}:-y}
Ah, I thought it might be like that, one of those 'nested' things.
Nothing you can't do with those if you know how.
However, you can do this with subscript syntax:
variable=${var[2]:=y}
which either assigns to $variable the second character of $var, or
assigns "y" to both $variable and to the second character of $var.
Even softer.
You can also do ${var[2]::=z} to forcibly assign "z" to the second
character of $var.
Excellent.
(Actually the doc might not say exactly that due to a Yodl formatting
error, but that's what it is supposed to say. The part about a single
`-' in a separate word is correct and is what matters here.)
Ok, all good. Fact is, I'd not have a clue where I'd look to find that
information. Thanks both.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author