October 2001
Intermediate to advanced
1040 pages
22h 50m
English
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.
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 ... |