Calculating using let and expr

Calculating using let and expr

am 05.12.2007 00:21:14 von apogeusistemas

Hi:

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


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

Thank You Masters !

Re: Calculating using let and expr

am 05.12.2007 03:30:35 von cfajohnson

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

Re: Calculating using let and expr

am 05.12.2007 03:45:10 von Maxwell Lol

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 \)`

Re: Calculating using let and expr

am 05.12.2007 03:57:14 von Allodoxaphobia

On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
> apogeusistemas@gmail.com writes:
>
>> Can You tell me how execute this arithmetic operations using expr and
>> let ??
>
> let? I don't know what command 'let' is.

A question for comp.lang.basic

Re: Calculating using let and expr

am 05.12.2007 06:05:41 von Cyrus Kriticos

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.

Re: Calculating using let and expr

am 05.12.2007 06:59:03 von Bill Marcum

On 2007-12-05, Allodoxaphobia wrote:
>
>
> On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
>> apogeusistemas@gmail.com writes:
>>
>>> Can You tell me how execute this arithmetic operations using expr and
>>> let ??
>>
>> let? I don't know what command 'let' is.
>
> A question for comp.lang.basic

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

Re: Calculating using let and expr

am 05.12.2007 22:00:28 von spcecdt

In article ,
Bill Marcum wrote:
>On 2007-12-05, Allodoxaphobia wrote:
>> On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
>>> apogeusistemas@gmail.com writes:
>>>
>>>> Can You tell me how execute this arithmetic operations using expr and
>>>> let ??
>>>
>>> let? I don't know what command 'let' is.
>>
>> A question for comp.lang.basic
>
>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/