guide.bash.academy icon indicating copy to clipboard operation
guide.bash.academy copied to clipboard

Explanation in "Variables and Expansions" #p1.1.0_12 could be clearer

Open mario-d-s opened this issue 6 years ago • 3 comments

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-d-s avatar Sep 21 '18 11:09 mario-d-s

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 avatar Jul 30 '21 03:07 ernesto1

@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 avatar Aug 09 '21 08:08 mario-d-s

@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?

ernesto1 avatar Aug 17 '21 01:08 ernesto1