Learning Bash, potential bug or total misunderstanding regarding globbing.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
If your shell glob matches a directory, you'll get a listing of the _contents_ of that directory. Are you sure those listed files are in your current dir?
Never noticed this before. Seem like a bug to me because it only happens with ranges, unless it's like that person says it has something to do with locale settings- not sure what he means though. Case sensitivity can be set with shopt command 'shopt -u nocaseglob'.
This is not a bug and the following solves the issue:
Code:
env LC_COLLATE=C ls -d [A-Z]*
As already mentioned by jschiwal, it is a problem with locale settings. In particular the LC_COLLATE sequence determines the behavior of [A-Z] intervals. Many locale settings collate the upper and lower case letters in this way:
Code:
AaBbCc...XxYyZz
so that the interval A-Z matches all the letters except the last lower case "z". Other settings collate the sequence as
Code:
aAbBcC...xXyYzZ
so that the interval [A-Z] matches all letters except the first lower case "a". You can demonstrate this if you have a file beginning with "a" and a file beginning with "z" in the current directory. The command
This does not answer your question, but just to let you know that:
Code:
ls -ld [[:upper:]]*
works fine.
Given the explanation above, this is without any doubt the most portable way to match upper OR lower case letters. 1000 points to sycamorex for this great tip!
...
Why am I seeing files starting with lowercase letters here ?
Hi crispyleif!
Case sensitivity works in an ASCII character set. At least that is what I read in Richard Petersen's book "Linux: The complete Reference 6th Ed."
I don't think your distro (like mine also..) uses ASCII character sets but Unicode.
This is not a bug and the following solves the issue:
Code:
env LC_COLLATE=C ls -d [A-Z]*
As already mentioned by jschiwal, it is a problem with locale settings. In particular the LC_COLLATE sequence determines the behavior of [A-Z] intervals. Many locale settings collate the upper and lower case letters in this way:
Code:
AaBbCc...XxYyZz
so that the interval A-Z matches all the letters except the last lower case "z". Other settings collate the sequence as
Code:
aAbBcC...xXyYzZ
so that the interval [A-Z] matches all letters except the first lower case "a". You can demonstrate this if you have a file beginning with "a" and a file beginning with "z" in the current directory. The command
Code:
ls -d [A-Z]*
will miss one of this two!
And also thanks colucix!
for the most complete explanation ...
Books are never enough
Long live the community!!!
Nope. Because ls without arguments refers to the current directory. If you use the -d option the content of the current directory is not listed. To me this is the expected behaviour.
Tip of the day: to run a command ignoring its alias, you can "escape" it using backslash:
The first command does not expand to the content of /path/to/dir because of the -d option. The second one expands to the content of /path/to/dir/*, that is one level down because the wildcard is previously expanded by the shell. It equals to the following command:
Code:
ls -ld /path/to/dir/tcl /path/to/dir/temp /path/to/dir/test.sh /path/to/dir/tgs_check_image.jpg
anyway the content of the directories /path/to/dir/tcl and /path/to/dir/temp is not shown (as it would be without the -d option).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.