User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 426,011 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,596 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 827 | Replies: 6
Reply
Join Date: Nov 2007
Posts: 40
Reputation: picass0 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
picass0 picass0 is offline Offline
Light Poster

check input arguments is upper or lower case

  #1  
Jul 23rd, 2008
Is there any function in shell that enable to check for upper or lower case? i would like to check the input argumnets for upper or lower case.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,638
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 22
Solved Threads: 416
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: check input arguments is upper or lower case

  #2  
Jul 23rd, 2008
Perhaps use case/esac with a pattern of [a-z]+
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Apr 2008
Posts: 39
Reputation: omrsafetyo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 8
omrsafetyo omrsafetyo is offline Offline
Light Poster

Re: check input arguments is upper or lower case

  #3  
Jul 23rd, 2008
Try this:
function test_upper {
test=`echo $1 | grep [A-Z]`

if [ "$?" = "0" ]; then
  #Uppercase letters found.
  #translate to lower case:
  echo $test | tr '[A-Z]' '[a-z]
else
   #letters are all lowercase, return them.
   echo $1
fi
}
Not exactly sure what you want your end result to be - but this for instance should find uppercase letters - if they are there, convert them to lowercase.
Basically, doing the grep for [A-Z] returns the argument provided if it has capital letters. If this happens, the return code ($?) is 0. If the return code is a 1, no capital letters were in the argument.
You can then run through all arguments.

You can apply this anyway you want though. Grep for [a-z] or [A-Z]. If the return code is 0, then the caps or lowercase were found and you can act accordingly.
Reply With Quote  
Join Date: Nov 2007
Posts: 40
Reputation: picass0 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
picass0 picass0 is offline Offline
Light Poster

Re: check input arguments is upper or lower case

  #4  
Jul 24th, 2008
thanks omrsafetyo!!!
Reply With Quote  
Join Date: Nov 2007
Posts: 40
Reputation: picass0 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
picass0 picass0 is offline Offline
Light Poster

Re: check input arguments is upper or lower case

  #5  
Jul 24th, 2008
i would like to know wheather is there a way thats i can check multiple arguments at the same time? bcos i got 3 args to input then i would like to check this 3 args for uppercase.
Reply With Quote  
Join Date: Apr 2008
Posts: 39
Reputation: omrsafetyo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 8
omrsafetyo omrsafetyo is offline Offline
Light Poster

Re: check input arguments is upper or lower case

  #6  
Jul 24th, 2008
with my above function:

while [ "$*" != "" ]
do
   working_arg=`test_upper $1`
   if [ "x${working_arg}x" != "xx" ]; then
      echo "$working_arg is all lowercase."
   fi
   shift
done
... or

for arg in "$*"
do
   test_upper $arg
done
if you want something simpler.

You could, for instance, rewrite the test_upper function to return a 1 or a 0, depending on whether or not it found uppercase. (You could simple use "echo $?" to "return" this value). Then, when you loop the arguments, you can have a variable that holds whether or not the case you are testing for was found (globally). e.g.

CAPS=0
for arg in "$*"
do
   if [ `test_upper $arg` -eq 0 ]
   then
      CAPS=1
   fi
done

if [ $CAPS -eq 1 ]
then
  #blah blah blah
fi
Last edited by omrsafetyo : Jul 24th, 2008 at 2:55 pm.
Reply With Quote  
Join Date: Apr 2006
Posts: 140
Reputation: ghostdog74 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 26
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: check input arguments is upper or lower case

  #7  
Jul 25th, 2008
Look at the bash guide here. It has examples on checking for upper case.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC