1. 程式人生 > >compare two digital

compare two digital

linux bash

#! /bin/bash
read -p "please input two numbers:" a b
if [ -z "$a" ] || [ -z "$b" ];then
echo " please input digital."
exit 2
fi
expr $a + 1 &> /dev/null
a1=echo $?
expr $b + 1 &> /dev/null
b1=echo $?
if [ "$a1" -ne 0 ] || [ "$b1" -ne 0 ];then
echo "you input is not digital."
exit 2
fi

if [ $a -gt $b ];then
echo "$a is bigger than $b."
elif [ $a -eq $b ];then
echo "$a equal $b"
else
echo "$a is small than $b"
fi

compare two digital