how to perform a basic arithmetics from unix csh/tcsh shell

vehomzzz picture vehomzzz · Sep 16, 2009 · Viewed 53.9k times · Source

Under windows, when I need to perform a basic calculations, I use a built-in calculator. Now I would like to find out what is the common way if you only have a shell.

Thanks

Answer

From this web page (for csh and derivatives, since you asked):

% @ x = (354 - 128 + 52 * 5 / 3)
% echo Result is $x
Result is 174

and

% set y = (354 - 128 + 52 / 3)
% echo Result is $y
Result is 354 - 128 + 52 / 3

notice the different results.

Personally, I stick to /bin/sh and call awk or something (for maximal portability), or others have exhibited the bash approach.