|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
doneLast 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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|