Skip to Main Content
UNIX® Shells by Example, Third Edition
book

UNIX® Shells by Example, Third Edition

by Ellie Quigley
October 2001
Intermediate to advanced content levelIntermediate to advanced
1040 pages
22h 50m
English
Pearson
Content preview from UNIX® Shells by Example, Third Edition

12.3. Arithmetic

12.3.1. Integers (declare and let Commands)

The declare Command. Variables can be declared as integers with the declare –i command. If you attempt to assign any string value, bash assigns 0 to the variable. Arithmetic can be performed on variables that have been declared as integers. (If the variable has not been declared as an integer, the built-in let command allows arithmetic operations. See “The let Command” on page 732.) If you attempt to assign a floating point number, bash reports a syntax error. Numbers can also be represented in different bases such as binary, octal, and hex.

Example 12.6.
1   $ declare –i num

2   $ num=hello
    $ echo $num
    0

3   $ num=5 + 5
						bash: +: command not found

4   $ num=5+5
    $ echo $num
    10

5   $ num=4*6 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

UNIX® Shells by Example Fourth Edition

UNIX® Shells by Example Fourth Edition

Ellie Quigley
Storage Area Networks For Dummies®

Storage Area Networks For Dummies®

Christopher Poelker, Alex Nikitin

Publisher Resources

ISBN: 013066538XPurchase book