标签:col put $1 求和 技术 inf style AC bubuko
#! /bin/bash ## For get the sum of tow numbers ## Writen by Qinys ## Date:2018-06-26 a=1 b=2 sum=$[$a+$b] echo "$a+$b=$sum"
上述是一个简单的shell脚本求和
a与b分别是变量,上述脚本的意思是对a,b两个变量分别赋值,然后求和
数学计算要用[]括起来并且外面加一个“$”
#! /bin/bash ## Input param to sum ## Writen by Qinys ## Date:2018-06-26 read -p "Please input a number:" x read -p "Please input another number:" y sum=$[$x+$y] echo "The sum of the two numbers is:$sum"
使用read –p输入相应的参数,注意:在x前边是有引号的
#! /bin/bash ## Writen by Qinys ## Date:2018-06-22 sum=$[$1+$2] echo "sum‘s value is : $sum"
运行结果为
标签:col put $1 求和 技术 inf style AC bubuko
原文地址:https://www.cnblogs.com/OliverQin/p/9229802.html