making sure my string is [a-z] only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting making sure my string is [a-z] only
# 15  
Old 04-24-2009
Sorry, I cannot reproduce (there is a syntax error in the example you posted, a missing space after the first == operator, is it a typo?).

Could you copy/paste the exact command(s) you are running and all the output you get?
# 16  
Old 04-24-2009
inicidentally, ive tried within my script doing this

Code:
#!/bin/bash
LANG=C

echo "Please enter VAR: "
read VAR

case $VAR in
  "" | *[!a-z]* ) echo invalid ;;
              * ) echo ok ;;
esac

Still returns OK when a capital letter is input Smilie
# 17  
Old 04-24-2009
Try with LC_ALL instead of LANG. Is the case-less version working?
# 18  
Old 04-24-2009
apologies for the syntax error, I corrected the space and it all works fine, script below

Code:
if [[ $VAR == *[^[:lower:]]* || $VAR == "" ]] ; then
echo invalid
else
echo ok
fi

just to let you know though that I cant seem to get the "LANG=C" within the script way to work.

Thank you very very much for your help Radoulov
# 19  
Old 04-24-2009
Perhaps a solution ???

echo $var | grep -E [a-z]
# 20  
Old 04-24-2009
Quote:
Originally Posted by hcclnoodles
[...]just to let you know though that I cant seem to get the "LANG=C" within the script way to work.
Even after setting LC_ALL=C (see my previous post)?
# 21  
Old 04-24-2009
LC_ALL works ! .

thank you again

Code:
#!/bin/bash
LC_ALL=C
read VAR


case $VAR in
  "" | *[!a-z]* ) echo invalid ;;
              * ) echo ok ;;
esac

~
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

2. Shell Programming and Scripting

I could use some help with making a script

I run a small instrument lab. We track our user's time on the instruments with a very manual process of 'last wtmp.1' then cut/paste data into spreadsheets. My boss makes the initial spreadsheets then I convert and format them for uploading into our billing software (COReS). Cores is looking for a... (8 Replies)
Discussion started by: jpontius
8 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. UNIX for Advanced & Expert Users

Regarding help for making own OS

Dear Fellow, I want to make my own OS, Kindly suggest from where i should start. please help me out. (2 Replies)
Discussion started by: zaigham_tt
2 Replies

5. Shell Programming and Scripting

Making array of string with bash

in.txt libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer-0_10-plugins-base Output should be: libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer0_10-plugins-base Then: #!/bin/sh v=(libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good... (5 Replies)
Discussion started by: cola
5 Replies

6. Shell Programming and Scripting

Making Variables

Dear Friends, Here I need your help once again. I have a flat file with pipe de-limited format e.g. 12345|1234567890|0|0|0| (Total 5 values) I want to take all non 0 ("Zero") values in variables named as anu1, anu2, anu3, anu4 and anu5. Is it possible? Please guide me. Thank you in... (3 Replies)
Discussion started by: anushree.a
3 Replies

7. UNIX and Linux Applications

help making a library.

I understand how to use vi and emacs but I have a project which entails building a library application like a phone directory or listing of dvd's. I am lost on where to start. any help would be appreciated. (1 Reply)
Discussion started by: gustave
1 Replies

8. Shell Programming and Scripting

making use of a Semaphore

can any one tell me how to run a semaphore. i understand roughly how they work code wise, but i'm not sure how to make use of them. i have two client programs in csh that perform tasks on a server file (flat file) how the i get the semaphore to lock the file when one has accessed it and how to use... (5 Replies)
Discussion started by: FDavid
5 Replies

9. UNIX for Dummies Questions & Answers

making a variable as string

I am evaluating a variable from a database and storing it as inside. The value of the variable is alpha numeric.How can i make this a string type.Any functions for the same. (1 Reply)
Discussion started by: dr46014
1 Replies
Login or Register to Ask a Question