Hi,
How can I check numeric value in shell?
I am passing one parameter (integer) and I want to restrict any other characters except 0-9.
./script xyz 10
Here 2nd parameter (10) should be integer only.
Can anyone help on this?
Malay
Hi,
How can I check numeric value in shell?
I am passing one parameter (integer) and I want to restrict any other characters except 0-9.
./script xyz 10
Here 2nd parameter (10) should be integer only.
Can anyone help on this?
Malay
if [[ ! -z $(echo $2 | sed 's/[0-9]//g') ]]
then
echo "integer only"; exit
fi
should work
#echo "1234" | awk '/^[0-9]+$/'
1234
#echo "12sasd34" | awk '/^[0-9]+$/'
#
Here's an oneliner:
awk -v x=$a 'END{if(x==x+0) print "integer"}' /dev/null
In this example , a is shell variable.
If a=10, then the output of above is "integer"
If a="10abhishek", then the output of above is ""
I want get system open file table value , Can u help.
Thanking you,
Mahesh
With bash (extglob option must be on) and ksh :
if [[ "$var" != +([0-9]) ]]
then
echo "Not an Integer"
fi
Jean-Pierre.
case $2 in
*[^0-9]*) echo not integer; exit 1 ;;
esac