LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Unexpected output from 'ls' when using glob expressions (http://www.linuxquestions.org/questions/linux-general-1/unexpected-output-from-%27ls%27-when-using-glob-expressions-207249/)

psiakr3w 07-19-2004 11:57 PM

Unexpected output from 'ls' when using glob expressions
 
I get the following output when running the command 'ls [A-M]*' in one of my directories:

debug.test
debug.test~
Makefile
Makefile~
Makefile.example
mm.py*

mfiles:
mall
mclean
mclean~
mflags
mtests
mtests~

and just because I was interested I ran 'ls [a-m]*' in the same dir and got the following:

debug.test
debug.test~
mm.py*

mfiles:
mall
mclean
mclean~
mflags
mtests
mtests~

So, it looks like the lower-case version of the command works, but what about the upper-case version. Why am I getting all those lower-case results? I''m running Mandrake 10.0 by the way.

Dark_Helmet 07-20-2004 01:10 AM

I've got Red Hat 8, and I see something similar. Both (lowercase and uppercase) can be demonstrated as "broken". I'll give an example in a sec. However, it's not a problem with ls, it's a problem with bash. The shell is supposed to handle wildcard expansion, and then call the command. So ls just sees the list of files that bash says match your fileglob.

Anyway, the experiment I ran was this:
Code:

$ touch Makefile
$ touch makefile
$ touch MAkefile
$ ls [A-M]*
makefile  Makefile  MAkefile
$ ls [a-m]*
makefile
$ ls M[a-m]*
Makefile  MAkefile

So it looks like there is some inconsistent behavior, or it's something I don't quite understand. The lowercase version worked in the second example, but failed in the third. I dunno... I'm sure I'll lose some sleep over it though :)

whansard 07-20-2004 01:40 AM

/work/work# touch Makefile
/work/work# touch makefile
/work/work# touch MAkefile
/work/work# ls
total 3
1 . 3 .. 0 MAkefile 0 Makefile 0 makefile
/work/work# ls [a-m]*
0 makefile
/work/work# ls [A-M]*
0 MAkefile 0 Makefile

works here.

bash2 --version
GNU bash, version 2.03.0(2)-release (i486-pc-linux-gnu)
Copyright 1998 Free Software Foundation, Inc.


keep in mind with the globs, that it'll list directories contents with those starting letters too.

Dark_Helmet 07-20-2004 03:21 AM

I ran those examples in a completely clean directory; just the three bogus makefiles.

My bash version is a little different:
Code:

$ bash --version
GNU bash, version 2.05b.0(1)-release (i686-pc-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.

I checked the man page for bash to make sure there were no special cases for using the square brackets, and didn't see anything. Ugh... now I may be forced to download the code and look. Sometimes I wish I didn't know C... :)

whansard 07-20-2004 04:43 AM

i just tried it with 2.05a and got the same as i did before. maybe you have some ls alias that's messing things up.

Dark_Helmet 07-20-2004 10:39 AM

That's a good point, but I checked the output of alias, and nothing is listed for ls:
Code:

$ alias
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

And just to make absolutely sure:
Code:

$ for file in [A-M]*
> do
> echo ${file}
> done
makefile
Makefile
MAkefile

The other variations I did earlier give the same results in the for-loop format as well. I wish I was just pulling your leg, but those are the results I get. So bash is still my #1 suspect (or some other hidden/unknown setting).

psiakr3w 07-20-2004 10:35 PM

Thank you for the replies.

DarkHelmet, I actually have the same bash version as you do:
Code:

$ bash --version
GNU bash, version 2.05b.0(1)-release (i586-mandrake-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.

whansard, you said you had tried it with 2.05a but I have 2.05b, so maybe it's the shell after all.

whansard 07-22-2004 03:21 AM

i just compiled 2.05b from fedora core2's source rpm. i didn't apply any of the patches. look at all this crap. i got the same results i got before.
2 . 4 bash-2.05b-rereadline.patch
4 .. 4 bash-2.05b-restrict.patch
4 bash-2.02-security.patch 4 bash-2.05b-slow.patch
4 bash-2.03-paths.patch 4 bash-2.05b-subst.patch
4 bash-2.03-profile.patch 4 bash-2.05b-utf8.patch
4 bash-2.04-compat.patch 4 bash-2.05b-warnings.patch
4 bash-2.05-ia64.patch 4 bash-2.05b-xcc.patch
8 bash-2.05a-interpreter.patch 1504 bash-2.05b.tar.bz2
4 bash-2.05a-loadables.patch 32 bash-completion-20020220.tar.gz
8 bash-2.05a-requires.patch 1436 bash-doc-2.05b.tar.bz2
4 bash-2.05a-shellfunc.patch 20 bash.spec
4 bash-2.05b-003fix.patch 4 bash205b-001
8 bash-2.05b-complete.patch 4 bash205b-002
4 bash-2.05b-debuginfo.patch 4 bash205b-003
4 bash-2.05b-display.patch 4 bash205b-004
8 bash-2.05b-locale.patch 4 bash205b-005
4 bash-2.05b-manso.patch 4 bash205b-006
4 bash-2.05b-mbinc.patch 4 bash205b-007
4 bash-2.05b-overread.patch 4 dot-bash_logout
4 bash-2.05b-pgrp_sync.patch 4 dot-bash_profile
4 bash-2.05b-readline-init.patch 4 dot-bashrc
4 bash-2.05b-readline-oom.patch

this is the only file i used from it.
1504 bash-2.05b.tar.bz2


All times are GMT -5. The time now is 09:48 AM.