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

Re: glob executable vs. non executable




On 2022-10-27 13:02, Lawrence Velázquez wrote:
What about binary files that you cannot execute, like libraries,
images, audio files, tarballs, etc.?
Yeah, I'm trying to cover all the possibilities.  'file' seems the most informative but even then there's more to say.
     all_unx=( (#i)${~1}(N.^*) )

The ${~spec} form enables GLOB_SUBST for that substitution.
Thanks, that handles it.

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.
Ah! It's a test in series not in parallel.  I thought it was an OR, but it's an AND.
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*,@) )

Very good.  I couldn't find any documentation on that.
However, as I said earlier, it is not useful to consider symbolic
links "executable"

In my head the word might be 'actionable'.  Type some word at the prompt and press ENTER and sometimes something happens.  What I'm trying to nail down is all the possibilities and what sorts of species they can be.  In that frame of mind, a symlink is actionable so I consider it in the same category as any other actionable word.

, 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-*) )

Using "*" with "-" more or less covers this.
Excellent, this gives me bones to chew on.  Fantastic power there if I can learn to use it.

(1)  Whether a file is a "text file" is a characteristic of its
      contents and is not appropriate for a glob qualifier.
Quite right.  I see it the moment you say it.  Different job.
(2)  Determining whether a file is "text" is more complicated than
      you seem to think.
I know it.  'file' seems to use three separate tests.  So, come to think of it, that's a difficult thing to ask of the shell.  One might suppose it's easy but it ain't.
(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.

... just a 'for instance'.  But I see now that this is hardly the shell's business and even if it was, it would be one of those conditional expressions: > [ -T "$some_file" ] && echo "That does appear to be a text file but don't be too sure." <

Anyway my function works well and I rely on it, but there's always the next little gotcha.

Thanks Lawrence, you guys are so informative.  Learning zsh by myself would be next to impossible.






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