怎样用shell语言实现小数的加减乘除运算

如题所述

原来我拿shell写的计算器:[root@liuxitingtestdir]#catcalculator.sh#!/bin/bashecho"usage:1+3,qisquit"while[1]doread-p"->>"str1>>/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$oin+)awk'BEGIN{printf"=%.2f\n",'$a'+'$b'}';;-)awk'BEGIN{printf"=%.2f\n",'$a'-'$b'}';;\*)awk'BEGIN{printf"=%.2f\n",'$a'*'$b'}';;/)if[$b-eq0]thenecho0CanNOTbedenominator!continuefiawk'BEGIN{printf"=%.2f\n",'$a'/'$b'}';;#^)awk'BEGIN{printf"=%.2f\n",'$a'**'$b'}';;*)echoerror;;esacdone刚刚写的倒序输出:[root@liuxitingtestdir]#catdaoXuShuChu.sh#!/bin/bashecho"usage:123456,qisquit"while[1]doecho-n"Pleaswenternumber:"readnif[$n=='q']thenbreakfisd=0rev=""on=$necho"$n"while[$n-gt0]dosd=$(($n%10))#getRemaindern=$(($n/10))#getnextdigitrev=$(echo$rev$sd)doneecho"$oninareverseorder$rev"done
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网