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

Re: ${var:1:1:=y}



On 02/03/2015 04:18 PM, Lawrence Velázquez wrote:
On Feb 3, 2015, at 6:12 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

We can of course do this:

    variable=${var:=xy}

I'm wanting the naive expansion of that syntax to do this:

    variable=${var:1:1:=y}

... but it doesn't work. Can something like that be done?
(This is admittedly a non-answer, as I don't know whether there's a solution that's as succinct as you'd like.)

I would find that syntax (or something like it) very ambiguous. What would be assigned "y" in this case — `var`, or the slice of `var` that you were testing? Neither is obvious.

Sure, it could end up as a syntactical monster. I'd naively read it: assign to 'variable' either the value of the second character of 'var' (just one character), and if that does not exist, assign 'y'. If you were checking for more than one character and some of them existed, but some not, then things would get fuzzy indeed. Probably better left alone. Just asking.



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