strange bash problem with dotglob

482 views
Skip to first unread message

Andrew McGlashan

unread,
Oct 17, 2015, 4:55:18 AM10/17/15
to mlu...@googlegroups.com
Hi,

The strangeness is about dotglob output with bash and having extglob
always on.

Bash version detail:
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)


Start with this.

# ls -la
total 20
drwxrwxrwt 5 root root 4096 Oct 17 19:45 .
drwxr-xr-x 28 root root 4096 Sep 8 03:57 ..
-rw-r--r-- 1 root root 0 Oct 17 19:25 .a
-rw-r--r-- 1 root root 0 Oct 17 19:25 .A
-rw-r--r-- 1 root root 0 Oct 17 18:24 aaa
-rw-r--r-- 1 root root 0 Oct 17 18:24 AAA
-rw-r--r-- 1 root root 0 Oct 17 18:24 bbb
drwxrwxrwt 2 root root 4096 Oct 13 01:37 .ICE-unix
drwxr-xr-x 2 root root 4096 Oct 13 01:37 .winbindd
-rw-r--r-- 1 root root 0 Oct 17 19:24 .x
drwxrwxrwt 2 root root 4096 Oct 13 01:37 .X11-unix
-rw-r--r-- 1 root root 0 Oct 17 19:25 .z
-rw-r--r-- 1 root root 0 Oct 17 19:25 .Z
-rw-r--r-- 1 root root 0 Oct 17 18:24 ZZZ


This is [1]

shopt|egrep '(dotglob|extglob)';echo;for x in u s;do shopt -${x}
dotglob;shopt dotglob;echo *;echo;echo *(.)[a-z]*;echo;done;shopt -u dotglob


Output [1]
dotglob off
extglob on

dotglob off
aaa AAA bbb ZZZ

aaa AAA bbb

dotglob on
.a .A aaa AAA bbb .ICE-unix .winbindd .x .X11-unix .z .Z ZZZ

.a .A aaa AAA bbb .ICE-unix .winbindd .x .X11-unix .z




And this is [2]

shopt|egrep '(dotglob|extglob)';echo;for x in u s;do shopt -${x}
dotglob;shopt dotglob;echo *;echo;echo *(.)[a-Z]*;echo;done;shopt -u dotglob


Output [2]
dotglob off
extglob on

dotglob off
aaa AAA bbb ZZZ

aaa AAA bbb ZZZ

dotglob on
.a .A aaa AAA bbb .ICE-unix .winbindd .x .X11-unix .z .Z ZZZ

.a .A aaa AAA bbb .ICE-unix .winbindd .x .X11-unix .z .Z ZZZ




Now....

The difference between [1] and [2] is just the set being [a-z] or [a-Z] ...

So, with dotglob on, why does [1] give AAA and .A and not show .Z or ZZZ
when all I want should be the [a-z] set (lowercase) ???? I would expect
it not to show AAA .A .Z or ZZZ with this option.

I think that [2] gives what I expect though.

A.

Glenn McIntosh

unread,
Oct 17, 2015, 8:35:36 AM10/17/15
to mlu...@googlegroups.com
On 17/10/15 19:55, Andrew McGlashan wrote:
> The difference between [1] and [2] is just the set being [a-z] or [a-Z] ...
>
> So, with dotglob on, why does [1] give AAA and .A and not show .Z or ZZZ
> when all I want should be the [a-z] set (lowercase) ???? I would expect
> it not to show AAA .A .Z or ZZZ with this option.

The order is specified by LC_COLLATE, which is locale dependent and
might not be what you expect. A typical order interleaves the lower and
capital letters (ie, a A b B c C d D ... z Z).

You can use [[:lower:]] if you just want lowercase letters.

Glenn
--
sks-keyservers.net 0x6d656d65

Andrew McGlashan

unread,
Oct 17, 2015, 9:06:56 AM10/17/15
to mlu...@googlegroups.com

On 17/10/2015 11:35 PM, Glenn McIntosh wrote:
> On 17/10/15 19:55, Andrew McGlashan wrote:
>> The difference between [1] and [2] is just the set being [a-z] or [a-Z] ...
>>
>> So, with dotglob on, why does [1] give AAA and .A and not show .Z or ZZZ
>> when all I want should be the [a-z] set (lowercase) ???? I would expect
>> it not to show AAA .A .Z or ZZZ with this option.
>
> The order is specified by LC_COLLATE, which is locale dependent and
> might not be what you expect. A typical order interleaves the lower and
> capital letters (ie, a A b B c C d D ... z Z).

Thank you, that explains it very well. Although I don't seem to have
LC_COLLATE in my environment; at least I understand why I got this
behaviour though now.

> You can use [[:lower:]] if you just want lowercase letters.

Thanks
A.
Reply all
Reply to author
Forward
0 new messages