ENTRY

"Howto. Number check in Lunux Bash"

Date:August 22nd, 2014
Tags:
Comments: 0
  • Join date: 11-30-99
  • Posts: 12
View Counter:
  • 25 views
Rate it
Ad
Poll
  • Which CI tools are used in your enterprise?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

Following script makes 3 checks. 1 st var is not set, second is a number , last is not a number.

#!/bin/bash

expr ${var} + 1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error, not a number: ${var}"
fi

var1=113
expr ${var1} +  1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error, not a number: ${var1}"
fi

var2="113.a"
expr ${var2} + 1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Error, not a number: ${var2}"
fi

Output :

$ bash numbercheck.sh
Error, not a number: 113.a

have fun !

Be Sociable, Share!
 
Interesting entry?
VN:F [1.8.5_1061]
Rating: 0 (from 0 votes)
0 votes 'YES'  0 votes 'NO'


TAGS

RELATED
Pages
Posts

SOCIAL
Be Sociable, Share!

INCOMING SEARCH TERMS



Responces

Leave a Reply