Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'a quick tcsh alias for expressions' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
a quick tcsh alias for expressions
Authored by: bdm on Oct 22, '04 09:36:23PM

Here is a simple tcsh alias for quick calculations on the command line. Someone will tell us how to define it in bash too...

% alias calc 'echo "END{print \!:* }" | awk -f /dev/stdin'

Now you can calculate anything that awk can do in a single expression, or a list of expressions separated by commas:

% calc sin(2.3)*2^4.5
% calc log(512)/log(2), log(513)/log(2)
9 9.00282
% calc x=3,y=4,x^3/y
3 4 6.75

Do man awk to see what is possible. Note that you don't have to escape special characters, which is why the alias looks more complex than you'd expect. Make sure your bash version has that property too.


[ Reply to This | # ]