#!/bin/bash # i'm tired of doing 'echo "scale=blah; ibase=bluh; obase=doh; foo * bar" | bc' # so enter calc "4.35 * 9" and get an answer echo "Enclose your expression in quotes." all="$@" echo "${all}" echo "${all}" | \ awk 'BEGIN { FS=" " OFS="" expression="" } { scale=0 ibase=10 obase=10 count=1 while (count <= NF) { dectest=index($count,".") if (dectest != 0) { declen=length($count) - dectest if (declen > scale) { scale=declen } } expression=expression $count " " count++ } scale++ print "scale=" scale "; " expression }' | \ bc