LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-20-2009, 08:07 PM   #1
btacuso
Member
 
Registered: May 2009
Posts: 32

Rep: Reputation: 15
How to test for a range of digits?


Hi, I intend to test the equality of a variable to a range of digits or characters, something like this:

if [ "$line3" == [0-9] ]
then echo "$line3"
fi


I am aware that I could do it one at a time by not using [0-9] but it will be a longer code. Any help will be appreciated. Thanks a lot.

Last edited by btacuso; 05-20-2009 at 08:10 PM.
 
Old 05-20-2009, 08:17 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi,


Welcome to LQ!

Quote:
Originally Posted by btacuso View Post
Hi, I intend to test the equality of a variable to a range of digits or characters, something like this:

if [ "$line3" == [0-9] ]
then echo "$line3"
fi


I am aware that I could do it one at a time by not using [0-9] but it will be a longer code. Any help will be appreciated. Thanks a lot.


Close :}

Code:
if [[ "$line3" =~ [0-9] ]]; then
  echo "line3"
fi



Cheers,
Tink
 
Old 05-20-2009, 08:34 PM   #3
btacuso
Member
 
Registered: May 2009
Posts: 32

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by Tinkster View Post
Hi,


Welcome to LQ!





Close :}

Code:
if [[ "$line3" =~ [0-9] ]]; then
  echo "line3"
fi



Cheers,
Tink
You are a big help, Tink, I'm off to work now. Cheers.

Last edited by btacuso; 05-20-2009 at 08:35 PM.
 
  


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
I need help finding out last 4 digits s_b Linux - Newbie 1 10-16-2008 09:16 AM
BASH - convert single digits to double digits. rickenbacherus Programming 7 05-07-2008 07:53 AM
grep and digits gawain Linux - Software 7 02-20-2008 03:13 AM
test number within a range tostay2003 Programming 2 12-21-2007 09:42 AM
BASH : how to act based on test against a range of numbers hollywoodb Programming 4 07-06-2006 07:09 PM


All times are GMT -5. The time now is 04:23 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration