If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Numeric check

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-16-02, 05:11
mirage mirage is offline
Registered User
 
Join Date: Nov 2002
Posts: 2
Question Numeric check

I am trying to read a variable

read $2

how can I check whether the entered string is a number?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 11-18-02, 12:16
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
echo $yourvar | grep "^[0-9][0-9]*$" && print numeric || print non-numeric
Reply With Quote
  #3 (permalink)  
Old 06-25-03, 13:24
pstireman pstireman is offline
Registered User
 
Join Date: Jun 2003
Posts: 2
Here is another way to do it. This way will check decimals as well as whole numbers.

let TST=$1*1 && print $1 numeric || print $1 non-numeric 2>/dev/null

Last edited by pstireman; 06-25-03 at 13:46.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On