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

Re: CONDITIONAL EXPRESSIONS, string == pattern



> On Jul 24, 2021, at 11:30 PM, Eric Cook <llua@xxxxxxx> wrote:
> 
> so in:
> 
> eval echo 'test ${vs} == ${vp} && echo hi || echo lo'
> 
> zsh does the normal expansions of the line and passes the arguments to eval, since the single quotes prevented
> any possible expansions the result is:
> 
> echo test ${vs} == ${vp} && echo hi || echo lo
> 
> so the above line goes through the steps of expansions and ends up like so:
> 
> echo test ' str1  a2' '==' '[[:blank:]]##str1[[:blank:]]##[[:alnum:]][[:alnum:]]' && echo hi || echo lo
> 
> so /echo/ prints out the strings given to it, which succeeds, causing echo hi to run.

I'll just add that examining the full contents of 'r' would have
provided a big hint that 'test' wasn't being run at all.

    % cat /tmp/testing2.zsh
    setopt EXTENDED_GLOB NO_EQUALS

    vs=' str1  a2'
    vp='[[:blank:]]##str1[[:blank:]]##[[:alnum:]][[:alnum:]]'

    r=( ${(f)"$( eval echo 'test ${vs} == ${vp} && echo hi || echo lo' )"} )
    typeset -p r

    % zsh -f /tmp/testing2.zsh
    typeset -a r=( 'test  str1  a2 == [[:blank:]]##str1[[:blank:]]##[[:alnum:]][[:alnum:]]' hi )

-- 
vq



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