Lower case test condition | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


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.

Lower case test condition

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-10-2012
newbie2010 newbie2010 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 4 December 2014, 2:36 PM EST
Posts: 174
Thanks: 79
Thanked 12 Times in 2 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 01:15 PM.. Reason: Code tags
Sponsored Links
    #2  
Old 12-10-2012
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 18 December 2014, 7:21 AM EST
Location: NM
Posts: 10,310
Thanks: 295
Thanked 821 Times in 763 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-11-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 17 December 2014, 4:49 PM EST
Location: Galactic Empire
Posts: 3,395
Thanks: 240
Thanked 1,211 Times in 1,137 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-11-2012 at 12:54 AM.. 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
newbie2010 newbie2010 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 4 December 2014, 2:36 PM EST
Posts: 174
Thanks: 79
Thanked 12 Times in 2 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
Closed Thread

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 03:53 PM
[Solved] Change Upper case to Lower case in C shell rockytodd Shell Programming and Scripting 3 11-04-2010 01:57 PM
data array needs to change upper case to lower case usustarr Shell Programming and Scripting 8 04-16-2010 06:33 PM
Script needed to select and delete lower case and mixed case records abhilash mn Shell Programming and Scripting 1 03-17-2008 09:00 AM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 01:07 AM



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