Why, if nocasematch is turned off, is case insensitive?

Given the following:

$ echo $BASH_VERSION
4.2.10(1)-release

$ shopt | fgrep case
nocaseglob      off
nocasematch     off

$ case A in [a-z]) echo TRUE;; esac
TRUE

I expect the capital letter A to not correspond to the minor character class [az] , but it is. Why doesn't this match fail?

+5
source share
2 answers

You cannot reliably use a dash in this way. If I do not use a dash, it works as expected:

$ bash --version
GNU bash, version 4.2.10(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ shopt -s nocasematch
$ case A in [abc]) echo TRUE;; esac
TRUE
$ shopt -u nocasematch
$ case A in [abc]) echo TRUE;; esac
$ 

But with a dash, it prints TRUE regardless of the setting nocasematch.

Bash . , , MIGHT [a-z] [A-Za-z]! , ( LC_COLLATE LC_ALL C). . .

, .

$ shopt -u nocasematch
$ case A in [a-z]) echo TRUE;; esac
TRUE
$ shopt -s nocasematch
$ case A in [a-z]) echo TRUE;; esac
TRUE
$ LC_ALL=C
$ shopt -u nocasematch
$ case A in [a-z]) echo TRUE;; esac
$ shopt -s nocasematch
$ case A in [a-z]) echo TRUE;; esac
TRUE
+7

. , .

, LC_COLLATE en_AU.utf8 ( ), , :

pax> case A in [a-b]) echo TRUE;; esac
TRUE
pax> _

, :

pax> case A in [ab]) echo TRUE;; esac
pax> _

, between a and b inclusive, A. A b, , .

, , , :

pax> export LC_COLLATE="C"
pax> case A in [a-b]) echo TRUE;; esac
pax> 

, , -:

( export LC_COLLATE="C" ; case A in [a-b]) echo TRUE;; esac )
+7

All Articles