if test is x numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if test is x numbers
# 1  
Old 10-16-2007
Question if test is x numbers

Using "if" I was wonder if there is a way that I could test if a varible was 7 numeric numbers?

example (the following would pass the test):
0000000
1234567
5555555
9999999

example (the following would fail):
000000
123456
a234567

Thanks in advance.
# 2  
Old 10-16-2007
Code:
#!/bin/sh

NUM=$1

case $1 in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
    echo numeric
    ;;
* )
    echo not
    ;;
esac

# 3  
Old 10-17-2007
Quote:
Originally Posted by porter
Code:
#!/bin/sh

NUM=$1

case $1 in
[0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
    echo numeric
    ;;
* )
    echo not
    ;;
esac

Porter works great thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Decimal numbers and letters in the same collums: round numbers

Hi! I found and then adapt the code for my pipeline... awk -F"," -vOFS="," '{printf "%0.2f %0.f\n",$2,$4}' xxx > yyy I add -F"," -vOFS="," (for input and output as csv file) and I change the columns and the number of decimal... It works but I have also some problems... here my columns ... (7 Replies)
Discussion started by: echo manolis
7 Replies

2. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

3. Shell Programming and Scripting

if test for higher value between 2 decimal numbers

Hi I would like to test for a max number value. It may be a decimal so I know I have to pipe into bc. I just cannot get the syntax for this to work. I cannot get passed an error with the bracket - see below. Any help appreciated. Regards Ewan This works: /export/home/ewan> cat... (5 Replies)
Discussion started by: emjs
5 Replies

4. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

6. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies
Login or Register to Ask a Question