2

I write below shell script to check whether given character is in uppercase or lowercase..

read d
case $d in
[a-z]) echo "Character is in Lowercase";;
[A-Z]) echo "Character is in Uppercase";;
esac

But when I enter any case in Uppercase it displays the output "charecter is in Lowercase" I just want to create simple script with basic programming. Is there any solution??

Anthon
  • 78,313
  • 42
  • 165
  • 222
Dip
  • 650
  • 3
  • 6
  • 13
  • please format your question: http://unix.stackexchange.com/editing-help – Sundeep Aug 13 '16 at 09:33
  • 1
    The script, as it stands now, works for me. – Kusalananda Aug 13 '16 at 09:45
  • 1
    What do you mean by "when I enter any case in Uppercase"? – Kusalananda Aug 13 '16 at 09:58
  • 1
    Iteresting. I always get lowercase in bash, but it works in dash, ksh, and zsh. – Petr Skocik Aug 13 '16 at 10:03
  • Correction : When i enter any uppercase letter as an input then also it gives output "Character is in Lowercase" – Dip Aug 13 '16 at 10:09
  • 7
    Isn't it a matter of collation order? See for example [Why does \[A-Z\] match lowercase letters in bash?](http://unix.stackexchange.com/questions/227070/why-does-a-z-match-lowercase-letters-in-bash) – steeldriver Aug 13 '16 at 10:29
  • on bash, `Z` gives uppercase and all other gives lowercase... if you interchange the two statements, `a` gives lowercase and every other letter gives uppercase.. I think it may be because case does [pattern matching](http://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching) and not regex matching – Sundeep Aug 13 '16 at 10:33
  • 1
    See steeldriver's link. Insert as second line: `LC_COLLATE=C` – Cyrus Aug 13 '16 at 11:10

0 Answers0