Unexpected output from 'ls' when using glob expressions
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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...
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.