Tiny Core Base > TCB Tips & Tricks
awkcalc.sh
MakodFilu:
As a one-liner, I thought of it more as a trick rather than a script.
--- Code: ---#!/bin/sh
echo '$*'|awk '{print "'$*'="'$*'}'
--- End code ---
--- Code: ---tc@box:~$ awkcalc 2^10
2^10=1024
tc@box:~$ awkcalc 2**10
2**10=1024
tc@box:~$ awkcalc 2*10
2*10=20
tc@box:~$ awkcalc '(1+1/2^20)^(2^20)'
(1+1/2^20)^(2^20)=2.71828
--- End code ---
Note the quotations in that last call.
roberts:
Cool! Yeah awk!
jls:
--- Code: ---tc@box:~$ echo $((1+1))
2
--- End code ---
robc:
sh math :D
--- Code: ---#!/bin/sh
echo $@ = $(($@))
--- End code ---
http://www.linuxconfig.org/Bash_scripting_Tutorial#17-arithmetic-operations
Note: ash treats ^ as xor, not as exp
MakodFilu:
The way it is done in sh is via ** operator.
Anyway, here is more syntactic sugar:
http://www.grymoire.com/Unix/Awk.html#uh-34
--- Code: ---tc@box:~$ awkcalc "sqrt(2)"
sqrt(2)=1.41421
tc@box:~$ awkcalc "sqrt(2)"
sqrt(2)=1.41421
tc@box:~$ awkcalc "2**(1/2)"
2**(1/2)=1.41421
tc@box:~$ awkcalc "2^(1/2)"
2^(1/2)=1.41421
tc@box:~$ awkcalc "20%8"
20%8=4
--- End code ---
I just decided galculator.tcz had way too much features that I absolutely didn't need (:
Navigation
[0] Message Index
[#] Next page
Go to full version