Calculating using let and expr

Hi:

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


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

Thank You Masters !
apogeusistemas [ Mi, 05 Dezember 2007 00:21 ] [ ID #1885892 ]

Re: Calculating using let and expr

On 2007-12-04, apogeusistemas [at] 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
cfajohnson [ Mi, 05 Dezember 2007 03:30 ] [ ID #1885898 ]

Re: Calculating using let and expr

apogeusistemas [at] 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 \)`
Maxwell Lol [ Mi, 05 Dezember 2007 03:45 ] [ ID #1885899 ]

Re: Calculating using let and expr

On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
> apogeusistemas [at] 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
Allodoxaphobia [ Mi, 05 Dezember 2007 03:57 ] [ ID #1885901 ]

Re: Calculating using let and expr

apogeusistemas [at] 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 480-$number*8192/1024
$ echo $a
-113704

--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
Cyrus Kriticos [ Mi, 05 Dezember 2007 06:05 ] [ ID #1885906 ]

Re: Calculating using let and expr

On 2007-12-05, Allodoxaphobia <bit-bucket [at] config.com> wrote:
>
>
> On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
>> apogeusistemas [at] 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.
Bill Marcum [ Mi, 05 Dezember 2007 06:59 ] [ ID #1885909 ]

Re: Calculating using let and expr

In article <slrnflcfh7.6qs.marcumbill [at] lark.localnet>,
Bill Marcum <marcumbill [at] bellsouth.net> wrote:
>On 2007-12-05, Allodoxaphobia <bit-bucket [at] config.com> wrote:
>> On 04 Dec 2007 21:45:10 -0500, Maxwell Lol wrote:
>>> apogeusistemas [at] 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 [at] armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
spcecdt [ Mi, 05 Dezember 2007 22:00 ] [ ID #1885933 ]
Linux » comp.unix.shell » Calculating using let and expr

Vorheriges Thema: Exporting a config file into the environment
Nächstes Thema: simple command that just won't work?