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

Re: question about glob qualifier format (#qx)



On Sep 21,  7:39am, Han Pingtian wrote:
}
} But I'm still confusing on the manpage :)
} 
} If I want to list all symbolic links and directories in current
} directory, this expression doesn't work:
}     
}     $ echo (*(#q@)|*(#q/))

A few lines above the excerpt you previously quoted from the manual, it
says:

  If the option EXTENDED_GLOB is set, a different syntax for glob
  qualifiers is available, namely `(#qx)' where x is any of the same glob
  qualifiers used in the other format.  The qualifiers must still appear
  at the end of the pattern.

} I cannot see any difference between '(#qx)' format and 'bare glob
} qualifier' format on being disabled by '|', '('. Please advise.

The difference is with e.g. (.).  With BARE_GLOB_QUAL, *(.) matches all
plain files.  With NO_BARE_GLOB_QUAL, *(.) matches files whose name ends
in a dot, and *(#q.) is needed to match all plain files.

} we must write it as :
} 
}     $ echo *(#q@) *(#q/)

  More than one of these lists can be combined, separated by commas. The
  whole list matches if at least one of the sublists matches (they are
  `or'ed, the qualifiers in the sublists are `and'ed).

So:

    % echo *(#q@,/)      

*should* do what you want, but see below about potential bugs ....

I accidentally encountered some odd behavior while confirming this.
With NO_EXTENDED_GLOB, #q is not supposed to be available to introduce
qualifiers.  However

    % setopt NO_EXTENDED_GLOB
    % echo *(#q@)
    <list of symlinks>

Whereas

    % echo *(#q/)
    zsh: unknown file attribute

This is inconsistent, that is, sometimes (#q@) will also give "unknown"
and (#q/) will work.  The more I play with it the less consistently it
behaves.  *(#q@,/) may produce any of
    zsh: unknown file attribute
    zsh: bad pattern: *(#q@,/)
or the intended list of files, depending on ... well, I can't tell what
it depends on, possibly previous globs or what the current directory is,
or how often EXTENDED_GLOB or BARE_GLOB_QUAL have been toggled on and
off.  In fact once I even got:

    % setopt CSH_NULL_GLOB
    % print -l *(#q@) *(#q/)
    zsh: bad pattern: *(#q/)

(even when */ matches several directories, and *(/) matches them with
BARE_GLOB_QUAL).  So something about the parsing for #q may be wonky.

All of this works very nicely when BARE_GLOB_QUAL is enabled, which it
is by default, which is probably why nobody noticed before that #q is
doing strange things.



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