Bird
0
0

Which of the following is the correct syntax to multiply two variables a and b using arithmetic expansion in bash?

easy📝 Syntax Q3 of 15
Bash Scripting - Quoting and Expansion
Which of the following is the correct syntax to multiply two variables a and b using arithmetic expansion in bash?
Aresult=$(a * b)
Bresult=$[a * b]
Cresult=$((a * b))
Dresult=a * b
Step-by-Step Solution
Solution:
  1. Step 1: Recall arithmetic expansion syntax

    Use $(( expression )) to evaluate math expressions.
  2. Step 2: Evaluate options

    result=$((a * b)) correctly uses $((a * b)). result=$(a * b) uses command substitution, which is incorrect. result=$[a * b] uses deprecated syntax. result=a * b assigns a string.
  3. Final Answer:

    result=$((a * b)) -> Option C
  4. Quick Check:

    Correct multiplication syntax = result=$((a * b)) [OK]
Quick Trick: Use $(( )) to multiply variables, not $() or plain strings [OK]
Common Mistakes:
MISTAKES
  • Using $() instead of $(( ))
  • Using deprecated $[] syntax
  • Assigning math as string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes