News for hackers. Stuff that matters.
Re:Justpath to explore PATH environment variable quickly by epogrebnyak on Monday February 26, 2024 @02:14PM (#39515626)
How does (N[-1]) get resolved?
Re:Justpath to explore PATH environment variable quickly by arp242 on Monday February 26, 2024 @05:31PM (#39517530)
(N) sets the NULL_GLOB option for that pattern:

    % print doesnt-exist*
    zsh: no matches found: doesnt-exist*
    % print doesnt-exist*(N)
    (doesn't print anything, pattern is just ignored)
([n]) is array indexing to get entry n; -1 gets the last entry:

    % print a*
    a-1 a-2 a-3
    % print a*([-1])
    a-3
    % print a*([1])
    a-1
Globbing is automatically sorted by name.

So putting that together, things like this:

      ~/.local/share/gem/ruby/*/bin(N[-1])  # Ruby
will use the latest Ruby version in ~/.local/share/gem/ruby, and it won't error out if it doesn't exist (so I can freely copy this around even to machines without Ruby, or remove Ruby, etc).
Re:Justpath to explore PATH environment variable quickly by epogrebnyak on Tuesday February 27, 2024 @03:43PM (#39529622)
Thanks for explaining, looks very clever. Is this syntax part of bash?
Re:Justpath to explore PATH environment variable quickly by arp242 on Tuesday February 27, 2024 @07:39PM (#39532366)
No, bash has nothing like this. It's all very specific to zsh. They're called "glob qualifiers" if you want to find out more.