|
From: | John Kearney |
Subject: | Re: [Help-bash] Smart way to override nocaseglob for a single glob? |
Date: | Thu, 07 Mar 2013 05:41:08 +0100 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 |
Am 04.03.2013 06:02, schrieb Dan
Douglas:
Not sure if you want this on the command line or in scripts.On Monday, March 04, 2013 01:38:57 AM Marcel Partap wrote:Dear folks, because of the improvement it gives when working in mixed case environments (f.e. when working with digital photos from FAT volumes - often the extension might be uppercase - *.jpg will not match these without nocaseglob) I have the flag universally enabled. But every now and then, I checkout some software repository and would like to have a gaze at the docs, historically uppercase text files in the project's root directory like README, INSTALL, NEWS, TODO.. However, with nocaseglob enabled, the expedient "ls [[:upper:]][[:upper:]]*" returns *nothing*. Looking at the source I figured out the reason seems to be bash setting the REG_ICASE flag, which makes sense. The response of the regex function to completly drop the [:upper:] character class is unexpected behaviour for me, but hardly a bug. Can anyone come up with something more elegant then f.e.( shopt -u nocaseglob; ls -d /usr/src/repositories/*/[[:upper:]][[:upper:]]* ); shopt nocaseglob? Not that the issue can't be worked around, but^^ #Regards!MarcelMaybe a regular old character range: LC_COLLATE=C; echo [A-Z]* Or an alias (untested): { alias withCase=$(</dev/fd/0); } <<-\EOF if shopt -q nocaseglob; then PROMPT_COMMAND=$(</dev/fd/0) shopt -u nocaseglob fi <<-EOG shopt -s nocaseglob unset -v PROMPT_COMMAND eval \${PROMPT_COMMAND:=$(printf %q "$PROMPT_COMMAND")}; EOG EOF ksh93 has a pattern modifier syntax: echo ~(Ni)* is equivalent to: `shopt -s nocaseglob nullglob' up until the next ~(...) or the end of the pattern. However you sacrifice a lot of the other interactive features that come with Bash, and it would take a ton of scripting to add them back. if its in scripts maybe you should do it the other way around. i.e. just not use nocaseglob, it is also be more portable. *.[jJ][pP][gG] if its for the command line, can't think of any generic bash solution i like I'd probably just use use find instead. find -maxdepth 1 -name '*.jpg' find -maxdepth 1 -iname '*.jpg' # ignore case find -maxdepth 1 -name '[[:upper:]][[:upper:]]*.jpg' |
[Prev in Thread] | Current Thread | [Next in Thread] |