I found a solution to my particular problem. I can quote the dir, and then remove the quoting of the spaces afterwards. myfiles() { emulate -L zsh setopt LOCAL_OPTIONS EXTENDED_GLOB local dir="${(q)1:a}/" dir=${dir/\\\ / } local filepattern="${dir}**/*" print -c ${~filepattern} } I realize this could brake on even more exotic file names, but for now I'm happy with this solution. On Thu, May 7, 2015 at 7:21 PM, Jesper Nygårds wrote: > On Thu, May 7, 2015 at 7:00 PM, Peter Stephenson > wrote: > >> $dir contains a straight string with unquoted parentheses. The >> ~filepattern then turns those parentheses into pattern characters. >> >> Yes, I understand. > > >> I'm not sure why you want filepattern anyway, but >> >> I tried to simplify my function to make my problem obvious. In my "real" > function, I am collecting several function arguments into a combined > pattern, which is why I need to use this indirect method. > > local filepattern="**/*" > >> print -c ${dir}${~filepattern} >> >> ought to work. Otherwise you'll need to quote metacharacters in dir, >> which is possible but should be unnecessary. >> > > Yes, but as my second example demonstrates: if I quote my filepattern, it > then doesn't work for files with spaces in their names. I was hoping for a > solution where it would be possible to get this to work for both situations. > > >