Lower case test condition

I want to locate directories that are upper, lower or have both upper and lower cases.

What I have is:

find /tmp/$var2 -type d' " ); [ -d $dir ] && echo "host case is incorrect" || echo "host case is correct" 

This actually is part of a larger script and it does work but the problem is that it will report "case is correct" if the user enters an upper case directory and the upper case directory is there. If they enter lower case, and the lower case directory is there, it reports "case is correct." But what if both upper and lower case directories (for example, DAVID and david) exist?

I want to have the script say both upper and lower directories are there but I am not sure if I use [[:upper]] or if there is some test condition that will assist with this.

On the other hand, if there is only an upper case directory and no lower, I just want it to say "host case is correct."

Any assistance is appreciated. I have not much experience with test conditions and am not sure if I am on the right path.

Posting more of your code would help a lot.

Here is a quick way to check mixed or all uppercase case:

[ "$dir" !=  $(echo "$dir" | awk '{tolower($0); print $0}') ] && echo "Same" || "mixed" 
1 Like
#!/bin/bash

for DIR in $( find . -type d | sed 's/\.\///g' )
do
        if expr match "$DIR" "[[:lower:]]*$" > /dev/null
        then
                echo "$DIR - Lowercase"
        elif expr match "$DIR" "[[:upper:]]*$" > /dev/null
        then
                echo "$DIR - Uppercase"
        elif expr match "$DIR" "[0-9]*$" > /dev/null
        then
                echo "$DIR - Numeric"
        elif expr match "$DIR" "[a-zA-Z0-9]*$" > /dev/null
        then
                echo "$DIR - Alphanumeric"
        elif expr match "$DIR" "[a-zA-Z]*$" > /dev/null
        then
                echo "$DIR - Mixed"
        fi
done
1 Like

These replies are exactly what I needed! Thanks for helping. I'm learning so much from all your posts!:slight_smile:

I did not know how to use "$DIR" "[[:upper:]]*$" collation and this explained it.