zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: "Ray Andrews" <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: glob executable vs. non executable
Date: Thu, 27 Oct 2022 16:02:37 -0400	[thread overview]
Message-ID: <05065e8d-8bf7-4ca2-b89d-1151348cb30d@app.fastmail.com> (raw)
In-Reply-To: <22b55ee0-ab85-1352-87a7-32dde5c7678d@eastlink.ca>

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


  reply	other threads:[~2022-10-27 20:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27 15:41 Ray Andrews
2022-10-27 20:02 ` Lawrence Velázquez [this message]
2022-10-27 21:44   ` Ray Andrews
2022-10-27 23:19     ` Lawrence Velázquez
2022-10-27 23:39       ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05065e8d-8bf7-4ca2-b89d-1151348cb30d@app.fastmail.com \
    --to=larryv@zsh.org \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).