Bird
0
0

How can you multiply two integer variables x and y and store the result in z in bash?

hard🚀 Application Q9 of 15
Bash Scripting - Variables
How can you multiply two integer variables x and y and store the result in z in bash?
Az=$((x * y))
Bz=expr $x \* $y
Cz=x*y
Dz=$x*$y
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate multiplication syntax

    Using z=$((x * y)) correctly multiplies x and y.
  2. Step 2: Check other options

    z=$x*$y and C assign strings; z=expr $x \* $y uses expr but with correct syntax (backslash is escaped properly).
  3. Final Answer:

    z=$((x * y)) -> Option A
  4. Quick Check:

    Use $(( )) for multiplication in bash [OK]
Quick Trick: Use $((x * y)) to multiply integers [OK]
Common Mistakes:
MISTAKES
  • Assigning string expressions
  • Not escaping * in expr
  • Missing $(( ))

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes