Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: glob executable vs. non executable
On Thu, Oct 27, 2022, at 11:41 AM, Ray Andrews wrote:
> I'm trying to break all 'real' files -- ignoring those weird 'special'
> files that linux makes -- into two groups: executables, which I take to
> be x-scripts, binaries and symlinks
Symbolic links are generally not considered to be executable files.
They may appear to have executable permissions, but those are usually
ignored. What matters are the permissions of the targets.
> vs. everything else, basically
> unx-scripts and plain text files.
What about binary files that you cannot execute, like libraries,
images, audio files, tarballs, etc.?
> $ eval "all_unx=( (#i)$1(N.^*) )"
There's almost certainly no need to use eval for this. If $1
contains a globbing pattern, then you can allow its value to be
used as such like so:
all_unx=( (#i)${~1}(N.^*) )
The ${~spec} form enables GLOB_SUBST for that substitution.
https://zsh.sourceforge.io/Doc/Release/Expansion.html#index-GLOB_005fSUBST_002c-toggle
> ... that seems to work for the later, the dot excludes symlinks but
> includes executables so: '^*' excludes those. But what's the converse?
> I'm wanting:
>
> $ eval "all_x=( (#i)$1(N*@) )"
>
> ... but it's a bad pattern.
It's not a bad pattern; the qualifiers are just impossible to
satisfy. You are asking for regular executable files that are ALSO
symbolic links.
> I can append two searches, one for '*' the
> other for '@' but I'm betting there's a clean way of doing it.
Strictly speaking, you could use a comma to separate the "*" and
"@" qualifiers; this denotes a logical disjunction. (Juxtaposition
indicates a conjunction.)
all_unx=( (#i)${~1}(N*,@) )
However, as I said earlier, it is not useful to consider symbolic
links "executable", so this result does not make any sense. You
probably want to find executables and *symbolic links that point
to executables*. This can be done with the "-" qualifier, which
causes the subsequent qualifiers to operate on symbolic links'
targets instead of on the links themselves.
all_unx=( (#i)${~1}(N-*) )
> Basically real files that whence is interested in vs. real files she is
> not interested in. Given that these glob qualifiers have a quite
> astonishing power, it seems puzzling that ... well, I shouldn't presume
> it isn't already there, but in my mind:
>
> $ eval "all_matches=( (#i)$1(NX )"
>
> ... anything whence finds, anything executable that is a file.
Using "*" with "-" more or less covers this.
> Oh, and
> while I'm imagining new glob qualifiers, how about 'T': any text file,
> (un)executable script or just a cookie recipe but made of readable text.
(1) Whether a file is a "text file" is a characteristic of its
contents and is not appropriate for a glob qualifier.
(2) Determining whether a file is "text" is more complicated than
you seem to think.
(3) If you have a utility or some code that does that to your
satisfaction, you can use it to filter the globbing results
via the "e" qualifier.
(4) The "T" qualifier is already in use.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author