问题
#!/bin/ksh
a=8.3
b=10.20
diff=`expr $b - $a`
echo "$diff"
its giving
expr: 0402-046 A specified operator requires numeric parameters. error i want output as 1.9
回答1:
You don't need bc for this, use the native arithmetic operators in ksh
#!/bin/ksh
a=8.3
b=10.20
printf "%.2f\n" "$((b - a))"
outputs
$ ksh script.ksh
1.90
来源:https://stackoverflow.com/questions/41059906/unix-shell-scripting-subtraction-for-floating-point-numbers