Results 1 to 3 of 3

Thread: Numeric check

  1. #1
    Join Date
    Nov 2002
    Posts
    2

    Question Unanswered: Numeric check

    I am trying to read a variable

    read $2

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

    Thanks.

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    echo $yourvar | grep "^[0-9][0-9]*$" && print numeric || print non-numeric

  3. #3
    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 14:46.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •