LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to test for a range of digits? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-test-for-a-range-of-digits-727408/)

btacuso 05-20-2009 07:07 PM

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.

Tinkster 05-20-2009 07:17 PM

Hi,


Welcome to LQ!

Quote:

Originally Posted by btacuso (Post 3547545)
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

btacuso 05-20-2009 07:34 PM

Quote:

Originally Posted by Tinkster (Post 3547549)
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.


All times are GMT -5. The time now is 12:48 PM.