LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-02-2003, 02:32 PM   #1
Shinobi
Member
 
Registered: Mar 2003
Posts: 46

Rep: Reputation: 15
Exclamation Calling All Script Guru's


First I guess I should ask where the best place to ask script questions is. Anyone have any links?

Now the questions:


What I'm trying to configure is a script that takes an (random string) argument ( $1 ) and first determines if it is all upper case or lower case.


If possible I would like to also do this: If it is a mixture I would like to convert it to either all upper case or lower case. If not possible an exit and

echo "argument must be either all upper or lower case"

would suffice.



Next, later in the script, I need to convert that argument to it's alternative (all upper to lower, or vice versa)

Please do this in #!/bin/sh

Thanks!!!!
 
Old 04-02-2003, 02:54 PM   #2
bentz
Member
 
Registered: Mar 2003
Distribution: Fedora, Mac OSX
Posts: 362

Rep: Reputation: 30
Use something like this:

echo "blah BLAH BLaH" | tr [:upper:] [:lower:]
Output: "blah blah blah"

or

echo "blah BLAH BLaH" | tr [:lower:] [:upper:]
Output: BLAH BLAH BLAH
 
Old 04-02-2003, 02:55 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
I was about to say the same:
echo $1 | tr '[a-z]' '[A-Z]'

I've never seen a way to check the case directly but you could convert it one way and see if it is the same before and after the conversion.
 
Old 04-02-2003, 03:09 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Here is a very simple example
Code:
#!/bin/sh

BEFORE=$1
UPPER=`echo $1 | tr '[a-z]' '[A-Z]'`
LOWER=`echo $1 | tr '[A-Z]' '[a-z]'`

if [ $BEFORE == $UPPER ]; then
echo The test entered was UPPERCASE

        else
        if [ $BEFORE == $LOWER ]; then
        echo The test entered was LOWERCASE

                else
                echo The test entered was of MIXED case

        fi
fi
 
Old 04-02-2003, 03:18 PM   #5
Shinobi
Member
 
Registered: Mar 2003
Posts: 46

Original Poster
Rep: Reputation: 15
Dave, you're the man! Thanks !


I'll see if I can tweak it to adjust the mixed case.

EDIT: Just realized that mixed cases are automatically translated by the tr anyways . So in the end all that remains is UPPER and LOWER. -- less headache!


Thanks again!

Last edited by Shinobi; 04-02-2003 at 03:33 PM.
 
Old 04-02-2003, 03:24 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,165
Blog Entries: 54

Rep: Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796Reputation: 2796
I've never seen a way to check the case directly
How about

capCharS=ABCDEFGHIJKLMNOPQRSTUVWXYZ
expr index $@ ${capChars} >/dev/null
case $? in 0) printf "%s$@ has caps.\n";; esac

You could "echo $@ | grep -qe '[A-Z]'" but that's no fun doing input validation.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
Need Some Guru's to inspect this iptables script predator.hawk Linux - Security 8 11-11-2004 08:26 PM
calling another script to be run. sonesay Programming 2 05-23-2004 06:08 AM
calling all linux guru's MadcapMagician Linux - Hardware 2 01-02-2004 01:03 AM
calling all networking guru's!!! mj@change.co.nz Linux - Networking 3 11-22-2002 05:29 AM


All times are GMT -5. The time now is 07:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration