bash - Linux vs. Unix file wildcards -


i'm looking list of files in directory in linux starting capital letter. in unix, it's simple

ls [a-z]*

in linux, though, i'm seeing matches don't seem case-sensitive:

=> ls a.txt  b.txt  b.txt  c.txt  c.txt  => ls [a]* a.txt  => ls [ab]* a.txt  b.txt  => ls [abc]* a.txt  b.txt  c.txt 

 
=> ls [a-c]* a.txt  b.txt  b.txt  c.txt  c.txt

=> ls [b]* b.txt 

 
=> ls [a-c]* a.txt  b.txt  b.txt  c.txt

running same commands on unix side work i'd expect. way linux has behaved? it's easy enough work around awk, i'm not looking solution in way, i'm wondering if never noticed before. in advance.

the result depends on different shell options, particularly: nocasematch nocaseglob , lc_collate variable (used in sort, [-], etc.)

$ shopt extglob nocasematch nocaseglob extglob         off nocasematch     off nocaseglob      off   $ printf "%s\n" a b b c c | sort a b b c c 

so [a-c] range contains b , c, not a, [a-c] should contain not c.

$ printf "%s\n" a b b c c | lc_collate=c sort b c b c 

gives different result.

$ lc_collate=c ls [a-c]* 

should return expected result, syntax sets variable new process execution (ls), not in current shell process.

edit: comment, previous command wrong because expansion processed before lc_collate set, simplest split 2 commands.

$ export lc_collate=c $ ls [a-c]* 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -