shell calculator

  • Follow


Hi,
  in the hope that this may be useful for somebody, I created this
easy shell calculator. It just creates a C++ program, compiles it,
runs it, and removes it.

http://shell-calc.googlecode.com/

I just needed a powerful calculator (bitwise operators, hexadecimal
input/output, etc.), and found nothing appropriate.

  Daniel.
0
Reply danielgutson (12) 12/25/2009 7:16:51 AM

On 2009-12-25, Daniel de C?rdoba wrote:
> Hi,
>   in the hope that this may be useful for somebody, I created this
> easy shell calculator. It just creates a C++ program, compiles it,
> runs it, and removes it.
>
> http://shell-calc.googlecode.com/
>
> I just needed a powerful calculator (bitwise operators, hexadecimal
> input/output, etc.), and found nothing appropriate.

   I use:

calc() {
  awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
}

-- 
   Chris F.A. Johnson, author           <http://shell.cfajohnson.com/>
   ===================================================================
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   ===== My code in this post, if any, assumes the POSIX locale  =====
   ===== and is released under the GNU General Public Licence    =====
0
Reply Chris 12/25/2009 10:01:08 AM


In article <7pjgr3Fl2cU1@mid.individual.net>,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>On 2009-12-25, Daniel de C?rdoba wrote:
>> Hi,
>>   in the hope that this may be useful for somebody, I created this
>> easy shell calculator. It just creates a C++ program, compiles it,
>> runs it, and removes it.
>>
>> http://shell-calc.googlecode.com/
>>
>> I just needed a powerful calculator (bitwise operators, hexadecimal
>> input/output, etc.), and found nothing appropriate.
>
>   I use:
>
>calc() {
>  awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
>}

And I use:

    alias c "echo '\!*' | sed 's/:/;/g' | bc -l"

Once, though, I did something similar to what the OP proposes.
It was a C program that professed to be an expression evaluator.

The core of it was piping something into "gcc -" to create a shared lib,
then calling a function in that shared lib to get the "answer".

0
Reply gazelle 12/25/2009 2:20:40 PM

On 12/25/2009 05:01 AM, Chris F.A. Johnson wrote:
> On 2009-12-25, Daniel de C?rdoba wrote:
>> Hi,
>>    in the hope that this may be useful for somebody, I created this
>> easy shell calculator. It just creates a C++ program, compiles it,
>> runs it, and removes it.
>>
>> http://shell-calc.googlecode.com/
>>
>> I just needed a powerful calculator (bitwise operators, hexadecimal
>> input/output, etc.), and found nothing appropriate.
>
>     I use:
>
> calc() {
>    awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
> }
>

I use:

function ca ()
{
     awk "BEGIN{ print $* }"
}

is it any different?
0
Reply Younes 12/28/2009 9:06:07 AM

In article <hh9sdu$9hh$1@speranza.aioe.org>,
Younes Zouhair  <poboxy@gmail.com> wrote:
....
>>     Mr Perfect uses:
>>
>> calc() {
>>    awk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
>> }
>>
>
>I use:
>
>function ca ()
>{
>     awk "BEGIN{ print $* }"
>}
>
>is it any different?

His version just has a bunch of little quibbles that you probably don't
care about.  I won't go point-by-point, but note that the 'exit' in his
version is there just-in-case you are using an old, decrepit version of
AWK (the ones where it tries to read from standard input even if the
program consists of only a BEGIN clause).

0
Reply gazelle 12/28/2009 3:07:22 PM

2009-12-24, 23:16(-08), Daniel de C�rdoba:
>   in the hope that this may be useful for somebody, I created this
> easy shell calculator. It just creates a C++ program, compiles it,
> runs it, and removes it.
>
> http://shell-calc.googlecode.com/
>
> I just needed a powerful calculator (bitwise operators, hexadecimal
> input/output, etc.), and found nothing appropriate.
[...]

What about zsh's zcalc? It seems to have all of the above plus
benefits from zsh's wonderful line editor.

http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#SEC289

-- 
St�phane
0
Reply Stephane 12/30/2009 7:15:27 AM

5 Replies
977 Views

(page loaded in 0.417 seconds)

Similiar Articles:













7/20/2012 7:15:10 PM


Reply: