利用"$((...))"进行简单的数值运算

    我们可以利用declare来进行运算,比如 "declare -i num=$a+$b" 来计算两个数的和。另外还可以利用"$((..))"来计算。下面实现了用户输入2个变量,然后将两数相乘并输出结果。

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo -e "input 2 numbers,I will cross them !\n"
read -p "first number:" firstnumber
read -p "second number:" secondnumber
total=$(($firstnumber*$secondnumber))
echo -e "\n $firstnumber x $secondnumber is ==>$total"


 

 

posted @ 2014-04-06 16:22  Java2048  阅读(1)  评论(0编辑  收藏  举报  来源
个人网站