February 2001
Beginner to intermediate
448 pages
9h 2m
English
Command substitution uses the expression $(...), where the output of what is inside the parentheses replaces the expression. Arithmetic expansion uses a similar expression: $(( ... )).
An easy example demonstrates this. The following is a simple program for performing arithmetic expansion:
#!/bin/ksh a=5 b=6 c=$(( a*b )) echo "$a * $b equals $c"
At first glance, the reader is probably unsure what will happen with the echo command. Here is the output of the script (named Example55.ksh):
$ ./Example55.ksh 5 * 6 equals 30
Notice that the echo command does not expand the math, but gives it literally. A common error here is in removing the double quotes from around the echo command. Here is the program without the double quotes: ...
Read now
Unlock full access