help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Smart way to override nocaseglob for a single glob?


From: Dan Douglas
Subject: Re: [Help-bash] Smart way to override nocaseglob for a single glob?
Date: Sun, 03 Mar 2013 23:02:40 -0600
User-agent: KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; )

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!Marcel

Maybe 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.
-- 
Dan Douglas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]