LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 07: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 07:10 PM.
 
Old 05-20-2009, 07:17 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 07: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 07:35 PM.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:05 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
Open Source Consulting | Domain Registration