这部分主要讨论数学相关的shell脚本编程。
加法运算
新建一个文件“Addition.sh”,输入下面的内容并赋予其可执行的权限。
#!/bin/bash
echo “Enter the First Number: ”
read a
echo “Enter the Second Number: ”
read b
x=$(expr "$a" + "$b")
echo $a + $b = $x
输出结果:
[root@tecmint ~]# vi Additions.sh
[root@tecmint ~]# chmod 755 Additions.sh
[root@tecmint ~]# ./Additions.sh
“Enter the First Number: ”
12
“Enter the Second Number: ”
13
12 + 13 = 25
减法运算
#!/bin/bash
echo “Enter the First Number: ”
read a
echo “Enter the Second Number: ”
read b
x=$(($a - $b))
echo $a - $b = $x
注意:这里我们没有像上面的例子中使用“expr”来执行数学运算。
输出结果:
[root@tecmint ~]# vi Substraction.sh
[root@te