help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Kludge for handling REPL arithmetic expressions


From: Chris Elvidge
Subject: Re: Kludge for handling REPL arithmetic expressions
Date: Wed, 4 Aug 2021 11:12:01 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Lightning/5.4

On 03/08/2021 04:32 am, Eric Pruitt wrote:
I have a command setup in Bash that allows me to use "=" to do
arithmetic in an interactive session:

     ~$ = 1/42 * 9
     0.2142857142857143 (3/14)
     ~$ = log(2048, 2)
     11
     ~$ = 1/3 + 7
     7.333333333333333 (22/3)
     ~$ = x * 3
     22

I was intrigued by this. So tried:
=() { echo "scale=5; $@" | bc; }
as an experiment.
Seems to work for simple calculations.

A couple of questions, though.
1) How do you 'export -f ='? Or is it impossible?
2) How do you type in '= log(2048,2)' without getting a syntax error?


--
Chris Elvidge
England




reply via email to

[Prev in Thread] Current Thread [Next in Thread]