Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-10-2012
Registered User
 
Join Date: Nov 2012
Posts: 53
Thanks: 20
Thanked 0 Times in 0 Posts
Lower case test condition

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

What I have is:


Code:
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.

Last edited by Scott; 12-11-2012 at 12:15 PM.. Reason: Code tags
Sponsored Links
    #2  
Old 12-10-2012
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,660
Thanks: 165
Thanked 647 Times in 624 Posts
Posting more of your code would help a lot.

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


Code:
[ "$dir" !=  $(echo "$dir" | awk '{tolower($0); print $0}') ] && echo "Same" || "mixed"

The Following User Says Thank You to jim mcnamara For This Useful Post:
newbie2010 (12-11-2012)
Sponsored Links
    #3  
Old 12-10-2012
Yoda's Avatar
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,321
Thanks: 154
Thanked 742 Times in 714 Posts

Code:
#!/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


Last edited by Yoda; 12-10-2012 at 11:54 PM.. Reason: Added test for Alphanumeric
The Following User Says Thank You to Yoda For This Useful Post:
newbie2010 (12-11-2012)
    #4  
Old 12-11-2012
Registered User
 
Join Date: Nov 2012
Posts: 53
Thanks: 20
Thanked 0 Times in 0 Posts
Upper/lowercase check script

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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Conversion from Upper Case to Lower Case Condition based tsbiju Shell Programming and Scripting 12 07-08-2011 02:53 PM
[Solved] Change Upper case to Lower case in C shell rockytodd Shell Programming and Scripting 3 11-04-2010 12:57 PM
data array needs to change upper case to lower case usustarr Shell Programming and Scripting 8 04-16-2010 05:33 PM
Script needed to select and delete lower case and mixed case records abhilash mn Shell Programming and Scripting 1 03-17-2008 08:00 AM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 12:07 AM



All times are GMT -4. The time now is 08:26 AM.