Recall & Review
beginner
What does the arithmetic expansion syntax
$(( )) do in bash scripting?It allows you to perform arithmetic calculations inside the double parentheses and returns the result as a number.
Click to reveal answer
beginner
How would you add two numbers, 5 and 3, using arithmetic expansion in bash?
You write
$((5 + 3)). This will output 8.Click to reveal answer
beginner
Can you use variables inside
$(( )) for arithmetic operations?Yes, you can use variables without the $ sign inside
$(( )). For example, if a=4 and b=2, then $((a * b)) will output 8.Click to reveal answer
intermediate
What happens if you try to use floating point numbers inside
$(( )) in bash?Bash arithmetic expansion only supports integers. Using floating point numbers will cause errors or unexpected results.
Click to reveal answer
beginner
How can you assign the result of an arithmetic expansion to a variable in bash?
You can assign it like this:
result=$((expression)). For example, result=$((5 + 3)) assigns 8 to the variable result.Click to reveal answer
What will the command
echo $((10 / 3)) output in bash?✗ Incorrect
Bash arithmetic expansion only works with integers, so it performs integer division and outputs 3.
Which of the following is the correct way to multiply two variables
a and b in bash using arithmetic expansion?✗ Incorrect
Inside $(( )), variables are referenced without the $ sign. So
$(( a * b )) is correct.What will
echo $((2 ** 3)) output in bash?✗ Incorrect
The ** operator means exponentiation. 2 to the power of 3 is 8.
Which of these is NOT supported inside arithmetic expansion
$(( )) in bash?✗ Incorrect
Bash arithmetic expansion only supports integer math, so floating point division is not supported.
How do you assign the result of
7 + 5 to a variable named sum in bash?✗ Incorrect
You must use arithmetic expansion $(( )) to calculate the sum and assign it to the variable.
Explain how to use arithmetic expansion
$(( )) in bash to perform basic math operations with variables.Think about how you write math expressions inside the double parentheses and how variables are referenced.
You got /4 concepts.
Describe the limitations of arithmetic expansion
$(( )) in bash and how it handles division.Consider what happens when you divide numbers that don't divide evenly.
You got /4 concepts.