Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use bash calculator for floating point calculations and I have to use input redirection and backtick (`) symbol in scripts.

As normal bracket $[math operation] and expr doesn't support float calculation. Is there any other way to do float calculation directly instead of using bc in script. I don't like unnecessary input redirection and backtick (`) symbol for scripts.

result=`bc <<end
temp_divide=($x / $y)
temp_divide * $z
echo "final result is $result"
share|improve this question
up vote 1 down vote accepted

Bash doesn't support floating point arithmetics, so you are stuck with using bc for that. You could use self-written helper functions similar to float_eval, which makes using bc as an inline calculator a little bit easier.

If you don't have to use bash, you could also consider using zsh, which supports floating point operations. Example:

evnu@centraldogma ~ 
% ((val = 1.0))
evnu@centraldogma ~ 
% ((val = 2.2))
evnu@centraldogma ~ 
% echo $val
evnu@centraldogma ~ 
% ((val += 2.2))
evnu@centraldogma ~ 
% echo $val
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.