[kwlug-disc] The amazing colon trick in GLOB matching within [[ ]] for bash

Doug Moen doug at moens.org
Thu Mar 12 12:39:01 EDT 2026


The standard use of $HOME/.local/bin is mentioned here:
https://en.wikipedia.org/wiki/Freedesktop.org#Base_Directory_Specification

On Thu, Mar 12, 2026, at 4:23 PM, D. Hugh Redelmeier wrote:
>> From: Federer Fanatic <nafdef at gmail.com>
>
> I don't understand your posting.  Ignorance on my part.  Time for me to 
> learn.
>
> I've been using Bourne Shell since the late 1970s (when it came out).
> Most of that time I've actually been using BASH as if it were the Bourne 
> Shell (with history) and haven't carefully studied the extensions.
>
> I think that BASH's language is way too complicated and poorly designed.  
> But that's mostly OK for me since I use the Bourne Shell subset most of 
> the time.
>
>> I found this bit of
>> magic in one of them I was not aware of but actually needed (normally one
>> just uses an external command in bash, afterall it's a shell:
>> 
>> if [[ ":${PATH}:" == *":${HOME}/.local/bin:"* ]]; then echo YES; else echo
>> NO; fi
>> 
>> and you do not need to enable globbing via shopt, the glob pattern is not
>> =~ construct but a check for equality....amazing ability for bash later
>> versions.
>
> It turns out that BASH interprets right side of == within [[ ]] in a 
> surprising manner.  I always assume that an equality test is symmetric, 
> but not in BASH.  The right side of == is a pattern!  The actual rules 
> seem really hacky to me: quotes have a special-to-this-context meaning 
> (the manpage doesn't say what kind of quoting).  I always assumed that =~ 
> was used whenever you wanted pattern matching.
>
> The other surprise to me is ~/.local/bin.  I must have missed that 
> convention's introduction.  I take it that it is for the use of packages 
> that are being installed by a user.  Where is this documented?  I have it 
> on my $PATH but the directory does not exist (Fedora)..
>
> I assume that "the amazing colon trick" is really just adding : at either 
> end of $PATH so that every component begins and ends with :.
>
> _______________________________________________
> kwlug-disc mailing list
> To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
> with the subject "unsubscribe", or email
> kwlug-disc-owner at kwlug.org to contact a human being.


More information about the kwlug-disc mailing list