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

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



On Feb 3, 2015, at 7:39 PM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

> 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'.

See, that interpretation didn't occur to me at all :)

From zshexpn(1):

    If a ${...} type parameter expression or a $(...) type command
    substitution is used in place of "name" above, it is expanded first
    and the result is used as if it were the value of "name".

So you'd probably want something like this, except with variable
assignment instead of `echo`:

    % foo=
    % echo ${${foo:1:1}:-y}
    y
    % foo=a
    % echo ${${foo:1:1}:-y}
    y
    % foo=abcdef
    % echo ${${foo:1:1}:-y}
    b
    %

vq


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