标签:ret strong expr pts null .sh com bin file
[root@rainjin scripts]# cat judge.sh
#!/bin/bash
##############################################################
# File Name: judge.sh
# Version: V1.0
# Author: Rain Jin
# Blog Site: http://www.cnblogs.com/rainjin/
# Created Time : 2017-10-27 21:19:42
# Environment: CentOS 7.2 Kernal 3.10.0
##############################################################
#judging if the arguments you have entered are integers;
if [ $# -ne 2 ]
then
echo "USAGE:$0 INT1 INT2"
exit 1
fi
a=$1
b=$2
expr $a + 1 &>/dev/null
RETVAL_A=$?
expr $b + 1 &>/dev/null
RETVAL_B=$?
if [ $RETVAL_A -ne 0 -o $RETVAL_B -ne 0 ]
then
echo "one of your input is not int."
exit 1
fi
echo "a-b = $(( $a - $b ))"
echo "a+b = $(( $a + $b ))"
echo "a*b = $(( $a * $b ))"
echo "a/b = $(( $a / $b ))"
echo "a**b = $(( $a ** $b ))"
echo "a%b = $(( $a % $b ))"
标签:ret strong expr pts null .sh com bin file
原文地址:http://www.cnblogs.com/rainjin/p/7745325.html