LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 07-19-2004, 11:57 PM   #1
psiakr3w
LQ Newbie
 
Registered: Jul 2004
Posts: 27

Rep: Reputation: 15
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.
 
Old 07-20-2004, 01:10 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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
 
Old 07-20-2004, 01:40 AM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,305

Rep: Reputation: 66
/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.
 
Old 07-20-2004, 03:21 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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...
 
Old 07-20-2004, 04:43 AM   #5
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,305

Rep: Reputation: 66
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.
 
Old 07-20-2004, 10:39 AM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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).
 
Old 07-20-2004, 10:35 PM   #7
psiakr3w
LQ Newbie
 
Registered: Jul 2004
Posts: 27

Original Poster
Rep: Reputation: 15
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.
 
Old 07-22-2004, 03:21 AM   #8
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,305

Rep: Reputation: 66
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to paginate in the 'LS' command? jhecht Linux - Software 10 04-13-2010 06:15 AM
alias cs='cd $1; ls' milanche Linux - Newbie 11 09-13-2005 05:57 PM
Regexp/Glob Renegade498 Programming 3 03-30-2005 11:52 AM
Glob(): Undefined Function? HappyDude Programming 0 11-05-2003 07:10 PM
'ls' command... sramelyk Slackware 7 10-01-2003 12:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration