0

Suppose extglob is turned on in Bash (I use 5.0.11(1)-release (x86_64-apple-darwin18.6.0)) and we have a file with the name list89988777,,,,,+--.txt. I cannot get a , to work in extglob pattern with [...] unless I escape not just the comma but all that goes with it if the , is the first in a [..], which does not make sense to me. Hence:

ls *+([[:digit:]]|[\,\-\+]).txt works, so does

ls *+([[:digit:]]|[[:punct:]]|[-\,+]).txt as well as

ls *+([[:digit:]]|[[:punct:]]|[-+\,]).txt

but

ls *+([[:digit:]]|[\,-+]).txt does not work.

Problem can be solved with ls *+([[:digit:]]|[[:punct:]]|[-+]).txt, which works, or for that matter with ls *+([[:digit:]]|[[:punct:]]|[,-+]).txt which also works. But why is escaping , and all the other chars in a [...] necessary if the first char is a ,?

  • Of course, that makes sense. It is the - that creates the unintended pattern. – Glaucon Oct 24 '19 at 23:11
0

Credit goes to the user who answered the question in a comment (but then the comment vanished).

It is not the , but actually the - within [...] that causes the problem because it creates a range. Hence, escaping , is not necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.