2

The fish documentation explains that the math command is essentially a thin wrapper to bc. The bc documentation has further info about more complex ops:

If bc is invoked with the -l option, a math library is preloaded and the default scale is set to 20. The math functions will calculate their results to the scale set at the time of their call. The math library defines the following functions:

s (x) The sine of x, x is in radians.
c (x) The cosine of x, x is in radians.
a (x) The arctangent of x, arctangent returns radians.
l (x) The natural logarithm of x.
e (x) The exponential function of raising e to the value x.
j (n,x) The bessel function of integer order n of x.

Unfortunately, this doesn't work with math: math -l l(16)/l(2), for example, gets interpreted as a command substitution, and math "-l l(16)/l(2)" and math -l "l(16)/l(2)" are interpreted erroneously also.

Is there a nice way to input this quickly and efficiently?

1 Answer 1

2

Add this function to your fish configuration:

function bc; command bc -l $argv; end

Since math calls bc, this will take care or your issue.

3
  • 1
    The first bc is treated as a function name, while command bc is the actual program outside of the scope of the function. Am I reading that right? Apr 9, 2014 at 2:33
  • exactly so .... Apr 9, 2014 at 9:59
  • 1
    In fish 3.0.2 I see math is a builtin, no longer affected by this definition. Anyway, such alias will get you used to running math and bc in a way that won't work for others / on other machines. I recommend either directly running echo 'l(16)/l(2)' | bc -l, or making a function with different name e.g. mathl. Aug 6, 2020 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .