help-bash
[Top][All Lists]
Advanced

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

Re: case insensitivity for some branch in the case statement


From: Eric Blake
Subject: Re: case insensitivity for some branch in the case statement
Date: Fri, 1 Nov 2019 23:12:20 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1

On 11/1/19 10:46 PM, Peng Yu wrote:
This is cumbersome if the string is long. Is there anything like a switch
that just changes the case-sensitivity in a specific branch? Thanks.

Please don't top-post on technical lists.

This is REALLY gross, but:

case abC in
 abc) echo no;;
 *) shopt -s nocasematch ;;&
 abc) echo yes;;
esac

which echoes yes, because the first pattern (abc) does NOT match case-sensitively, the second pattern (*) _does_ match, and the ;;& terminator forces bash to recheck the input against the third pattern (abc) at which point it DOES match case-insensitively.

But PLEASE don't abuse bash like that in your scripts.

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




reply via email to

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