Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-08-2012, 10:02 PM   #1
Registered: Oct 2012
Location: Holden, ME, USA
Distribution: SlackWare64 14.00
Posts: 185

Rep: Reputation: 0
Bash: Checking for lower case and upper case letters in a string

So I have a case in my bash script or well a few that I need to check if a word is typed in any combination of upper and/or lower case letters (trust me I don't want to do "Back" | "BACK" | "back" | so on for every combination of upper and lower case characters of every thing that would add quite the length to my script.

Not only do I need this in case statements also need to be able to in an if statement where I compare the string "delete" and "Delete" and "DELETE" and so on to a variable.

why I'm so picky about this is when I name a file with anything thats the same word just different case it throws an error to the user and plus I also for ease of use want this. I would appreaciate some help on this as I'm struggling to find a simple answer.

I believe those are the only two situations I need this in thank you ahead of time you guys are great to me

oh and changing the variable before the rest of my script to all lowercase or uppercase isn't gonna cut it :P unless i ABSOLUTELY have to

found solution for if statements doing the whole [Aa][Bb] thing I was doing it wrong so it failed but now that works
if I do this to the case statement though things go very wrong when I type quit it exits...the terminal not just the script like it should :P any ideas? and funny thing is where I found this solution that worked for if statements the example on the site is a case statement :P yet it don't work :P before this test quit did exactly as it should btw

also another detail I would like to avoid shopt -u nocasematch if at all possible again it isn't gonna cut what I want but I may consider it since I believe I found a part of my script that if may have no choice but would like avoid it in the case section please if at all possible

so in a test I just did I found case isn't working because well I'm not sure yet but it wasn't the regex expressions so now to find whats wrong. but if anyone care to explain how useful shopt can be I'm listening but I'll be in a moment when I fix this look it up myself but any opinions? thanks

Just discovered the issue it's in the way I run the script. How can I make it if I run the script with . filename that when I do an exit 0 it doesn't quit the terminal too? ./filename doesn't do this nor does a symlink running it which probably be the main way of running the script but still I need it to not do this if it is to be run that way. Any ideas

all in all with no replies on this in time I have managed to fix this file up and have a couple bugs I wish to bring up I've found and see if anyone can help me but that is for another post this one is messy :P

Last edited by fatalerror0x00; 12-09-2012 at 01:07 AM.
Old 12-09-2012, 02:17 AM   #2
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,600

Rep: Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926Reputation: 2926
${VAR^^} #upper
${VAR,,} #lower
Once converted to all upper or lower case you only require a single test, ie "BACK"


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about creating files, and upper and lower case letters clifford227 Linux - Newbie 10 08-23-2012 05:02 AM
mkisofs -iso-level 1 converts to lower case instead of upper case. stf92 Slackware 3 10-29-2010 12:32 AM
Changing upper caseto lower case using Bash basildon Linux - Newbie 1 09-19-2008 05:53 AM
renaming directories from upper case to lower case, help!! linux_teller Linux - Newbie 3 03-07-2008 05:15 AM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 04:09 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:37 PM.

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