Arithmetic Operations in Shell
Level 3112 keystrokes
$(( )) evaluates integer arithmetic. With a=10 and b=3 it prints the sum, product, integer quotient (3, the fraction is dropped) and remainder (1).
Shell code
# Two assignments on one line: a=10 and b=31a=10 b=3# Inside $(( )) variables need no $: 10 + 3 = 132echo "Sum: $((a + b))"# Multiplication: 303echo "Product: $((a * b))"# Integer division drops the fraction: 10 / 3 = 34echo "Division: $((a / b))"# % gives the remainder: 10 % 3 = 15echo "Modulo: $((a % b))"Output
Sum: 13 Product: 30 Division: 3 Modulo: 1
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.
"× 8(× 8)× 8:× 4$× 4=× 2*× 1/× 1%× 1+× 1