[ILUG] Bash 2 and shell case matching
Niall
niall at magicgoeshere.com
Mon Apr 17 20:30:22 IST 2000
Hi all,
John Allen and I discussed this back and forth privately recently,
and I though I'd got a handle on it, but I haven't. It's to do with how bash
matches wildcard filespecs, and is seemingly related to the new shopt
command in Bash 2 and specifically the nocaseglob option. I jumped in here
when the action of the nullglob option bit me, but now it's the case thing
which is hurting me. I have a directory with some text files as below:
% ls *txt
All Haughey.txt General Irish.txt Scenes Foreign.txt
Business Foreign.txt Politics Foreign.txt Social Personalities.txt
Business Irish.txt Politics Irish.txt small.txt
I needed to do some operation on only those files beginning with capitals,
but for some reason I looked at what the expansion was before I did the work
which was just as well because:
% ls [A-Z]*txt
All Haughey.txt General Irish.txt Scenes Foreign.txt
Business Foreign.txt Politics Foreign.txt Social Personalities.txt
Business Irish.txt Politics Irish.txt small.txt
I didn't want small.txt here, nor did I expect it to match. This behaviour
is the same whether the shell option nocaseglob is set or not. If I have
only [A-S] instead of [A-Z] I get the behaviour I'd expect.
I get
% shopt -s nocaseglob;ls [A-S]*txt
All Haughey.txt General Irish.txt Scenes Foreign.txt
Business Foreign.txt Politics Foreign.txt Social Personalities.txt
Business Irish.txt Politics Irish.txt small.txt
% shopt -u nocaseglob;ls [A-S]*txt
All Haughey.txt General Irish.txt Scenes Foreign.txt
Business Foreign.txt Politics Foreign.txt Social Personalities.txt
Business Irish.txt Politics Irish.txt
This looks awfully like a bug to me, and a major one, I'd say, as files may
be included (e.g. for deletion) where you'd not expect them to be.
Kindest regards,
Niall O Broin
More information about the ILUG
mailing list