Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

shell calculator

7 views
Skip to first unread message

Daniel de Córdoba

unread,
Dec 25, 2009, 2:16:51 AM12/25/09
to
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.

Chris F.A. Johnson

unread,
Dec 25, 2009, 5:01:08 AM12/25/09
to

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 =====

Kenny McCormack

unread,
Dec 25, 2009, 9:20:40 AM12/25/09
to
In article <7pjgr3...@mid.individual.net>,

Chris F.A. Johnson <cfajo...@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".

Younes Zouhair

unread,
Dec 28, 2009, 4:06:07 AM12/28/09
to
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?

Kenny McCormack

unread,
Dec 28, 2009, 10:07:22 AM12/28/09
to
In article <hh9sdu$9hh$1...@speranza.aioe.org>,
Younes Zouhair <pob...@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).

Stephane CHAZELAS

unread,
Dec 30, 2009, 2:15:27 AM12/30/09
to
2009-12-24, 23:16(-08), Daniel de Cᅵrdoba:
[...]

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 new messages