Arithmetic

   

Korn Shell: Unix and Linux Programming Manual, Third Edition, The
By Anatole Olczak

Table of Contents
Appendix G.  Pdksh Quick Reference


Integer arithmetic is performed with the let and ((...)) commands. All of the operators from the C programming language (except ++, ?? and ?:) are supported by the Korn shell. The format for arithmetic constants is:


number
or
base#number

where base is a decimal number between 2 and 36 that specifies the arithmetic base. If not specified, the default is base 10. The arithmetic base can also be set with the typeset i command.

Arithmetic Commands

let "arithmetic-expression"

((arithmetic-expression))

evaluate arithmetic expression

integer variable

declare an integer variable

integer variable=integer-value

declare an integer variable and set it to a value

integer variable="arithmetic-assignment-expression"

declare an integer variable and assign it the value of the arithmetic-assignment-expression

typeset in variable[=value]

declare a base n integer variable, and optionally assign it a value

Arithmetic Operators

?/P>

unary minus

!

logical negation

~

bitwise negation

*, /, %

multiplication, division, remainder (modulo)

+, ?/P>

addition, subtraction

<<, >>

left shift, right shift

<=, <

less than or equal to, less than

>=, >

greater than or equal to, greater than

==, !=

equal to, not equal to

&

bitwise AND

^

bitwise exclusive OR

|

bitwise OR

&&

logical AND

||

logical OR

=

assignment

*=, /=, %=

multiply assign, divide assign, modulo assign

+=, ?

increment, decrement

<<=, >>=

left shift assign, right shift assign

&=, ^=, |=

bitwise AND assign, bitwise exclusive OR assign, bitwise OR assign

(...)

grouping (used to override precedence rules)


       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net