Arithmetic Operations in Shell
Level 4144 keystrokes
$(( )) evaluates an integer expression and inserts the result, while (( )) evaluates it without output, for example to increment a variable. a=10 and b=3 give 13, 30, 3, 1, and then a becomes 11.
Shell code
# ; separates two assignments on one line1a=10; b=3# $(( )) inserts the result: 132echo "Sum: $((a + b))"# 10 * 3 = 303echo "Product: $((a * b))"# Integer division, the fraction is dropped: 34echo "Division: $((a / b))"# Remainder of 10 / 3: 15echo "Modulo: $((a % b))"# (( )) evaluates without printing; a++ changes a to 116((a++))7echo "Incremented: $a"Output
Sum: 13 Product: 30 Division: 3 Modulo: 1 Incremented: 11
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Shell code and how often they appear.
"× 10(× 10)× 10:× 5$× 5+× 3=× 2;× 1*× 1/× 1