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
# 8  
Old 04-24-2009
Thanks radoulov for taking the time to respond to my post ... but do I really have to start changing locales etc just to perform a simple pattern match ??.... I would honestly prefer not to do it this way. Thanks for your help though.
# 9  
Old 04-24-2009
That's why I said to set the LANG variable only for the duration of the script or even only for the specific command (just like I did).

If you don't want to mess with the locale, you need to use a tool that recognizes the POSIX character classes (i.e. you'll need [:lower:]).

Which shell you are using (post the exact version, if possible)?
# 10  
Old 04-24-2009
am heading my script with

Code:
#!/bin/bash

im running Solaris 10

and the bash version is

Code:
$ /bin/bash -version
GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.

So unless I have a specific tool for POSIX, I cant use regex for pattern matching things like this ? would you be able to point me at an example of one of these tools

thank you again for your help on this
# 11  
Old 04-24-2009
oh by the way , can i just set "LANG=c" within my script ?

i tried looking at currently set system variables by typing "env" at the command line and "LANG" isnt in there ?

sorry for all the questions Smilie
# 12  
Old 04-24-2009
Quote:
Originally Posted by hcclnoodles
am heading my script with

Code:
#!/bin/bash

im running Solaris 10

and the bash version is
[...]
I believe that that version of bash supports POSIX character classes:

Code:
[[ $var == *[^[:lower:]]* || ! $var ]]&&echo invalid||echo ok


Last edited by radoulov; 04-24-2009 at 07:51 AM.. Reason: refactored
# 13  
Old 04-24-2009
Quote:
Originally Posted by hcclnoodles
oh by the way , can i just set "LANG=c" within my script ?
Yes.

Quote:
i tried looking at currently set system variables by typing "env" at the command line and "LANG" isnt in there ?
If I recall correctly if it isn't set explicitly a default value is assumed.
# 14  
Old 04-24-2009
I adjusted the code slightly to an 'if' statement, but unfortunately it still returns true if any capital letter is issued (anywhere in the string)... it will fail if a numneric is added however

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

so it looks like my bash supports POSIX but is still giving me problems
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