linux系统中shell脚本计算平方根 bc命令的使用

1、

脚本如下:

[root@centos79 test2]# cat test.sh
#!/bin/bash
if [ $# -ne 1 ]   ##  $#表示一共有几个参数
then
echo "usage bash test.sh number"
exit 1
else
echo "sqrt($1)" | bc        ## $1表示第一个参数
fi
[root@centos79 test2]# bash test.sh
usage bash test.sh number
[root@centos79 test2]# bash test.sh 100
10
[root@centos79 test2]# bash test.sh 100.0
10.0
原文地址:https://www.cnblogs.com/liujiaxin2018/p/15039080.html