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

Re: globbing in conditional expressions



On May 30,  9:47am, Peter Stephenson wrote:
}
} On Thu, 29 May 2014 20:59:56 -0700
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > } I couldn't get it to work via [ -z ]
} > 
} > Hmm, seems to work for me:
} >
} > torch% [ -z ba*(N) ] && echo OK 
} > OK
} > torch% [ ! -z ba*(NY) ] && echo OK
} > torch% [ ! -z co*(NY) ] && echo OK
} > OK
} 
} Is this null glob safe with [ ?  I get true from both "[ -n ]" and
} "[ -z ]" suggesting the case of an elided argument isn't properly
} handled.

Hm.  This is a side-effect of treating [ thing ] as [ -n thing ] :
[ -n ] becomes [ -n -n ] and [ -z ] becomes [ -n -z ].

Is there a non-convoluted way to have the special case of a glob with
BOTH of the (NY) qualifiers return empty string rather than nularg when
it finds no match?  Empty string is an illegal file name so for most
purposes it wouldn't otherwise affect usage.
 
} But this is specific to zsh --- why are we using [ rather than [[ anyway?

Because [[ ]] doesn't do globbing on its arguments, and this is a
filename generation rather than a pattern.  We messed around a few weeks
ago with trying to make [[ ]] do globbing and ran into tokenization
conflicts.



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