Arithmetic expansion#

If you want to perform a calculation and use the resulting base 10 string for something the syntax is $((EXPRESSION)). This is called arithmetic expansion because Bash expands (replaces) the arithmetic expression with a string when running the command, and the inside of the parentheses is called a numeric context because the expression is treated as arithmetic rather than a string. An example, printing the result of x² – y², should make this clearer:


This page is a preview of The newline Guide to Bash Scripting

No discussions yet