guide.bash.academy
guide.bash.academy copied to clipboard
Explanation in "Variables and Expansions" #p1.1.0_12 could be clearer
I had to read this paragraph (source) multiple times before I understood what was actually going on.
It explains how the glob !(my)*.txt
can match a file named myscript.txt
. Because I am familiar with how regex works, I was able to figure out why that happens, but the explanation in that page actually threw me off at first.
Perhaps it can be reworded so that what happens is more instantly clear.
Mario if you could lay down your explanation of this behaviour here I would appreciate it :D
I am also unable to articulate why !(my)*.txt
does not work.
@ernesto1
Think of it like breaking down the pattern in two parts: !(my)
and *.txt
. Given a path of myscript.txt
, the way bash matches the pattern is that m
matches !(my)
, and yscript
matches *.txt
so there is a complete match.
Possibly confusing no matter how you try to explain it :)
@mario-d-s that is the part that confuses me. Doesn't !(my)
have to match the whole word 'my', not just the individual letters?