LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-02-2015, 12:30 AM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

Rep: Reputation: Disabled
Issue in Metacharacter


Hi,

In 1st eg: Am trying to filter the files starting with small letters in first position and numeric in 2nd position. But it also retrieves capital letters. I dunno why.

In 2eg: Am trying to filter the files starting with capital letters in first position and numeric in 2nd position. But it also retrieves small letters in 1st position. I dunno why.

Let me know, if anyone knows the root cause of this.

[root@localhost ~]# ls -ltr [a-z][0-9]*
----rwxrwx 1 root root 10 Oct 29 23:03 a2.link
-rwxr--r-- 1 root root 19 Oct 29 23:04 a3.op
-rw-r--r-- 1 root root 31478 Oct 30 03:08 a20
-rw-r--r-- 1 root root 0 Nov 1 19:45 b123
-rw-r--r-- 1 root root 0 Nov 1 19:55 a2Bcat
-rw-r--r-- 1 root root 0 Nov 1 19:55 A2bcat
-rw-r--r-- 1 root root 0 Nov 1 20:06 a1
-rw-r--r-- 1 root root 0 Nov 1 20:32 a123
-rw-r--r-- 1 root root 0 Nov 1 20:32 a12
-rw-r--r-- 1 root root 0 Nov 1 20:32 a12as
-rw-r--r-- 1 root root 0 Nov 1 20:32 a12as!
-rw-r--r-- 1 root root 0 Nov 1 20:32 a122222

[root@localhost ~]# ls -ltr [A-Z][0-9]*
-rw-r--r-- 1 root root 0 Nov 1 19:45 b123
-rw-r--r-- 1 root root 0 Nov 1 19:55 A2bcat
[root@localhost ~]#
 
Old 11-02-2015, 04:06 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
See http://www.tldp.org/LDP/abs/html/globbingref.html & http://tldp.org/LDP/GNU-Linux-Tools-...tml/x11655.htm for 'globbing'.
This similar but less powerful than regexes.
If you want to use regexes, pipe the o/p through grep which does understand regexes.
 
Old 11-02-2015, 05:15 AM   #3
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
My guess is that you have LC_COLLATE (check the output of locale) set to something other than LC_COLLATE=C.
http://teaching.idallen.com/net2003/...acter_sets.txt
 
Old 11-02-2015, 08:50 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
allend - I must admit this caught me out as my computer also is returning odd info, but I did the following and still get erroneous data back?
Code:
$ LC_ALL=C ls [a-z]*
A2bcat  b123
So I too am looking forward to see why this suddenly does not work

chrism01 - I read through both pages supplied and one would think the above should behave differently??

On a little further testing, it would seem I have an ignore case set somewhere, however, I have also used my unaliased ls and get the same messed up results:
Code:
$ LC_ALL=C /bin/ls a*
A2bcat

Last edited by grail; 11-02-2015 at 08:54 AM. Reason: Extra testing
 
Old 11-02-2015, 09:25 AM   #5
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Hmm - curious. I see
Code:
bash-4.3$ locale
LANG=en_AU
LC_CTYPE="en_AU"
LC_NUMERIC="en_AU"
LC_TIME="en_AU"
LC_COLLATE=C
LC_MONETARY="en_AU"
LC_MESSAGES="en_AU"
LC_PAPER="en_AU"
LC_NAME="en_AU"
LC_ADDRESS="en_AU"
LC_TELEPHONE="en_AU"
LC_MEASUREMENT="en_AU"
LC_IDENTIFICATION="en_AU"
LC_ALL=
bash-4.3$ ls
A123  B123  a123  b123
bash-4.3$ ls [A-Z]*
A123  B123
bash-4.3$ ls [a-z]*
a123  b123
and unaliased, just to be sure.
Code:
bash-4.3$ \ls
A123  B123  a123  b123
bash-4.3$ \ls [a-z]*
a123  b123
bash-4.3$ \ls [A-Z]*
A123  B123
 
Old 11-02-2015, 07:04 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, I tried '\ls', but it made no difference; it still lists all the files.
(Centos 6.7 if that helps anyone)
Code:
 ls
a  a1  b  t.sh  t.t  T.T

 \ls [a-z]*
a  a1  b  t.sh	t.t  T.T

 \ls [A-Z]*
b  t.sh  t.t  T.T         # hmmm now THAT is odd; didn't list 'a' files

Last edited by chrism01; 11-02-2015 at 07:07 PM. Reason: odd result noted
 
Old 11-20-2015, 03:13 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
This one seemed to have fallen off the radar, but I am still in need of a solution myself as it is now affecting scripts and the like when using some of these conjunctions

I have an older machine in vm running bash 4.3.30 and it does not seem to have this issue. Do we think it might be a bash issue??
 
Old 12-13-2015, 11:39 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Thought I would give this one another touch to see if anyone has thought / heard of anything?

Here is yet another example of this weird behaviour I just ran into:
Code:
$ ls [D]*
d2.awk*  d2.rb*  d2.sh*  d.awk*  dd_mem_test.sh*  d.html  d.pl*  d.py*  d.rb*  d.sh*

# Also tried unaliased
$ \ls [D]*
d2.awk	d2.rb  d2.sh  d.awk  dd_mem_test.sh  d.html  d.pl  d.py  d.rb  d.sh
 
Old 12-14-2015, 02:27 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, it is quite an interesting one... iirc David_The_H (?) used to be a bit of a whiz at this stuff, but I haven't seen a post from him in a long time.

Whilst I'd love to see a definitive explanation, if you're using this for real (grail), then like I said above, I'd pipe it through eg grep and use real regexes.
 
Old 12-14-2015, 03:27 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Well if for real you mean on a regular basis, yes, as part of using my system I often use ls and with globbing. To then have to change to also include grep would seem overkill on such a simple task

Guess I will have to keep searching. It does surprise me that more people have not come across this issue (assuming it is a bash thing and not some sill setting I have somewhere)

Will let you know what I find
 
Old 12-14-2015, 05:33 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
I have a vm of my own design which does not have the issue and has latest bash. It would seem my distro provider (Manjaro) took it upon themselves to add the following to .bashrc:
Code:
shopt -s nocaseglob
Turning this off has resolved the most recent example:
Code:
$ ls
ruby/  tmp/  d2.awk*  d2.rb*  d2.sh*  d.awk*  dd_mem_test.sh*  d.html  d.pl*  d.py*  d.rb*  d.sh*  f1  f2  f3  f4  lxapp-fix-gtk3.sh*  mount_iso.sh*  pwd_gen.awk*  system_info.sh*  vimrc.txt
$ ls [D]*
ls: cannot access [D]*: No such file or directory
Unfortunately, it did not help for the ranges
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tilde metacharacter tooplayer20J Linux - Newbie 2 11-14-2014 03:04 PM
[SOLVED] grep metacharacter question. Grtyop Linux - Newbie 2 12-23-2013 05:28 AM
[SOLVED] sed end-of-line metacharacter $ not working qajaq Linux - Software 4 02-24-2013 10:31 PM
[SOLVED] how can backslash be executed as a metacharacter within single quotes? joham34 Programming 4 05-06-2011 01:52 PM
bash script, metacharacter protection sphynx Programming 4 04-22-2004 10:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:13 PM.

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