LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 01-25-2010, 03:01 PM   #1
gregarion
Member
 
Registered: Jan 2010
Posts: 69

Rep: Reputation: 15
Checking for Alphabets


Code:
echo -n "read this also:"
read NewAuthor


if [ -z $( echo "$NewAuthor" | tr -d '[[:digit:]]' ) ] ; then
echo "its a digit"
else
echo "something else"
fi
Hey guys , i am trying to do a search to check if the input is using alphabets and nothing else. I tried using [[:digit:]] and [[:alpha:]] but none seems to work


When i use digit, it read 22.k as alphabet and not as a wrong syntax.
For alpha , it does not allow me to input data which has spaces such as " hello world". how can i solve this issue.
 
Old 01-25-2010, 03:27 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
Assuming bash:

Code:
if [[ $testvar =~ [[:digit:]] ]]; then
     echo "String contains numbers."
else
     echo "No numbers found."
fi
Of course, just using [[:digit:]] only won't match non-alphabetical characters either, like punctuation marks or foreign scripts. You'll have to modify it for that.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
SquidGuard: filtering non-english alphabets jlregister Linux - Server 0 11-09-2007 06:33 AM
Checking In PitCritter LinuxQuestions.org Member Intro 1 12-28-2004 11:53 PM
French accented alphabets..... HELP!!!! arun79 Mandriva 1 03-17-2004 08:35 AM
Checking for X - no ziggamon Linux - Software 5 05-24-2003 02:32 PM
just checking... bandofmercy Linux - Hardware 1 03-28-2003 09:26 PM


All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
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