Unix Shell - Calculating using let and expr

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > Calculating using let and expr





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Calculating using let and expr
apogeusistemas@gmail.com

2007-12-04, 7:25 pm

Hi:

Can You tell me how execute this arithmetic operations using expr and
let ??


number=16773
a=(((20480-(($number *8192)/1024)))

Thank You Masters !
Chris F.A. Johnson

2007-12-05, 1:42 am

On 2007-12-04, apogeusistemas@gmail.com wrote:
>
> Can You tell me how execute this arithmetic operations using expr and
> let ??
>
>
> number=16773
> a=(((20480-(($number *8192)/1024)))


let is not standard, and expr is unnecessary:

a=$(( 20480 - ($number * 8192) / 1024 ))

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Maxwell Lol

2007-12-05, 1:42 am

apogeusistemas@gmail.com writes:

> Hi:
>
> Can You tell me how execute this arithmetic operations using expr and
> let ??
>


let? I don't know what command 'let' is.

>
> number=16773
> a=(((20480-(($number *8192)/1024)))


Try this:

number=16773
a=`expr 20480 - \( \( $number \* 8192 \) \/ 1024 \)`
Allodoxaphobia

2007-12-05, 1:42 am

On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
> apogeusistemas@gmail.com writes:
>
>
> let? I don't know what command 'let' is.


A question for comp.lang.basic
Cyrus Kriticos

2007-12-05, 1:42 am

apogeusistemas@gmail.com wrote:
>
> Can You tell me how execute this arithmetic operations using expr and
> let ??
>
>
> number=16773
> a=(((20480-(($number *8192)/1024)))


$ number=16773
$ let a=20480-$number*8192/1024
$ echo $a
-113704

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Bill Marcum

2007-12-05, 1:42 am

On 2007-12-05, Allodoxaphobia <bit-bucket@config.com> wrote:
>
>
> On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
>
> A question for comp.lang.basic


I think ksh has "let" as an alternative way of writing arithmetic
expressions.

John DuBois

2007-12-05, 7:23 pm

In article <slrnflcfh7.6qs.marcumbill@lark.localnet>,
Bill Marcum <marcumbill@bellsouth.net> wrote:
>On 2007-12-05, Allodoxaphobia <bit-bucket@config.com> wrote:
>
>I think ksh has "let" as an alternative way of writing arithmetic
>expressions.


Yes. I have a vague and possibly incorrect memory that the first ksh I used
had let but not (( )).

One use I've found for let is testing whether an expression is legal or not,
without producing an error message:

let "expression" 1 2>/dev/null || ...

The 1 ensures that if the expression is legal (and so let doesn't stop its
evaluations), let will give status 0; without that, it would give status 1 if
expression was legal but evaluated to 0.

John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com