1:用bc方法,你可以去查查
echo $us+$sy | bc
如我的结果
# echo $a
8.8
# echo $b
9.1
# echo $a+$b | bc
17.9
2:用awk方法
# awk -v a=$a -v b=$b 'BEGIN{print a+b}'
17.9
原来我�.shellåç计ç®å¨ï¼[root@liuxiting testdir]# cat calculator.sh #!/bin/bashecho "usage: 1+3 <Enter>,q <Enter>is quit"while [ 1 ]doread -p "->>" str 1>>/dev/nulla=`echo $str |awk -F '+|-|*|/' '{print $1}'`if [ $a == q ]thenbreakfib=`echo $str |awk -F '+|-|*|/' '{print $2}'`o=`echo $str |grep -o "[[:punct:]]" | grep -v "\."`case $o in+) awk 'BEGIN{printf " =%.2f\n",'$a'+'$b'}'-) awk 'BEGIN{printf " =%.2f\n",'$a'-'$b'}'\*) awk 'BEGIN{printf " =%.2f\n",'$a'*'$b'}'/)if [ $b -eq 0 ]then echo 0 Can NOT be denominator!continuefi awk 'BEGIN{printf " =%.2f\n",'$a'/'$b'}'#^) awk 'BEGIN{printf " =%.2f\n",'$a'**'$b'}'*) echo erroresacdone åååçååºè¾åºï¼[root@liuxiting testdir]# cat daoXuShuChu.sh #!/bin/bash echo "usage: 123456 <Enter>, q <Enter>is quit"while [ 1 ]doecho -n "Pleasw enter number : " read n if [ $n == 'q' ]then breakfisd=0 rev="" on=$n echo "$n" while [ $n -gt 0 ] do sd=$(( $n % 10 )) # get Remainder n=$(( $n / 10 )) # get next digit rev=$( echo $rev$sd) done echo "$on in a reverse order $rev" done欢迎分享,转载请注明来源:内存溢出
评论列表(0条)