千家信息网

operators usages

发表于:2024-11-26 作者:千家信息网编辑
千家信息网最后更新 2024年11月26日,#! /bin/bashif [ $# -ne 2 ];thenecho "please input two arguments:"exit 2fiexpr $1 + 2 &>/dev/nullif
千家信息网最后更新 2024年11月26日operators usages

#! /bin/bash
if [ $# -ne 2 ];then
echo "please input two arguments:"
exit 2
fi
expr $1 + 2 &>/dev/null
if [ $? -ne 0 ];then
echo "please input int."
exit 3
fi
expr $2 + 3 &>/dev/null
if [ $? -ne 0 ];then
echo "please input int."
exit 4
fi

echo "$1+$2 is $(($1+$2))"
echo "$1$2 is $(($1$2))"
echo "$1-$2 is $(($1-$2))"
echo "$1/$2 is $(($1/$2))"

0