Bart Schaefer wrote on Thu, May 15, 2014 at 07:50:03 -0700: > On May 15, 9:29am, Daniel Shahaf wrote: > } Subject: Re: globbing in conditional expressions > } > } Bart Schaefer wrote on Wed, May 14, 2014 at 00:18:19 -0700: > } > Do I read correctly that "shortcircuit" also means "don't return any > } > file names, just return an indication of whether there is such a file" > } > ?? (Since you don't allocate the matchbuf array when shortcircuit.) > } > } Of course. As soon as you find a single matching filename you return to > } the caller, so there are two options: either return just a boolean, or > } return the first matching filename in readdir() order (via $REPLY, as in > } Roman's post). I'm not sure how idiomatic it would be for a [[ -x ]] > } condition to set $REPLY. > > I would not suggest that [[ -m ... ]] set $REPLY, but why does -m have > to be the only place where short-circuiting occurs? I could imagine > adding a globbing flag (#X) [where I'm using X as a placeholder rather > than a suggestion for the actual flag] which means that the glob returns > only the first matching file it stumbles upon. > > In fact if you had that flag you wouldn't need -m as a condition op, it > would suffice to do [ ! -z pat(NX) ]. The implementation also would not > need to change the call signatures of any of the C functions ... That turned out to be much less code to implement. It's attached, if anyone finds it useful. I couldn't get it to work via [ -z ], but this works: % Src/zsh -fc '() { (( $#@ )) } *(NY); echo $?' 0 % Src/zsh -fc '() { (( $#@ )) } *foobar(NY); echo $?' 1