Bugzilla – Bug 940903
Bash ignores case when globbing
Last modified: 2015-08-13 06:58:49 UTC
Trying to select files using [a-z]* to only see files starting with lower case letter, bash gives me all files. Works fine in csh and ksh. Sample output: (bash is my login shell) gwb@callahans:~> echo [a-z]* Backups bin BOINC Calibre Library Desktop Documents Downloads gui_rpc_auth.cfg isos kde logs Music Pictures Public public_html RasPi RPMs src Templates tmp Videos gwb@callahans:~> csh /home/gwb% echo [a-z]* bin gui_rpc_auth.cfg isos kde logs public_html src tmp /home/gwb% exit exit gwb@callahans:~> ksh gwb@callahans:/home/gwb> echo [a-z]* bin gui_rpc_auth.cfg isos kde logs public_html src tmp gwb@callahans:/home/gwb> exit gwb@callahans:~> shopt nocaseglob nocaseglob off gwb@callahans:~> echo $LANG en_US.UTF-8 Setting or clearing noglobcase has no effect: gwb@callahans:~> shopt nocaseglob nocaseglob off gwb@callahans:~> echo [a-z]* Backups bin BOINC Calibre Library Desktop Documents Downloads gui_rpc_auth.cfg isos kde logs Music Pictures Public public_html RasPi RPMs src Templates tmp Videos gwb@callahans:~> shopt -s nocaseglob gwb@callahans:~> echo [a-z]* Backups bin BOINC Calibre Library Desktop Documents Downloads gui_rpc_auth.cfg isos kde logs Music Pictures Public public_html RasPi RPMs src Templates tmp Videos gwb@callahans:~> shopt nocaseglob nocaseglob on gwb@callahans:~> shopt -u nocaseglob
Same results on Tumbleweed 20150802.
Sorry but this is how bash works. Btw: nocaseglob does work cd /var/log echo [a-z]* | grep -E '^[A-Z]'| wc -c 0 shopt -s nocaseglob d136:log # echo [a-z]* | grep -E '^[A-Z]' | wc -c 439
No, this is not how bash should work. Another test: gwb@callahans:~> mkdir /tmp/playground gwb@callahans:~> cd /tmp/playground gwb@callahans:/tmp/playground> touch a A gwb@callahans:/tmp/playground> echo [a-z] a A gwb@callahans:/tmp/playground> echo [A-Z] A gwb@callahans:/tmp/playground> shopt -s nocaseglob gwb@callahans:/tmp/playground> echo [a-z] a A gwb@callahans:/tmp/playground> echo [A-Z] a A gwb@callahans:/tmp/playground> So nocaseglob does something, but it's still not right (or even consistent). The first echo should only show 'a'. As I said, this does work correctly (i.e., only displays the matching case) in both csh and ksh.
And even more strangeness... Continuing my last test: gwb@callahans:/tmp/playground> touch b B gwb@callahans:/tmp/playground> echo [A-Z] a A b B gwb@callahans:/tmp/playground> shopt -u nocaseglob gwb@callahans:/tmp/playground> echo [a-z] a A b B gwb@callahans:/tmp/playground> echo [A-Z] A b B So it works only on the first field???
Run bashbug and report upstream