BASH 中的运算只限于整数,要进行浮点运算的话,需要借助其他的程序,如 bc,awk,perl。
#!/bin/bash
#===============================================================================
#
# FILE: arithmetic.sh
#
# USAGE: ./arithmetic.sh
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: huys (), huys03@gmail.com
# COMPANY: HUYS .Inc
# VERSION: 1.0
# CREATED: 11/03/2008 01:39:05 PM CST
# REVISION: ---
#===============================================================================
sum=92.1
count=8
result=`perl -e "print $sum/$count"`
echo $result
result2=`echo $sum/$count | bc -l`
echo $result2
exit 0
|
阅读(1398) | 评论(0) | 转发(0) |