Bird
0
0

What will be the output of this script?

medium📝 Command Output Q5 of 15
Bash Scripting - Variables
What will be the output of this script?
declare -i x=10
declare -i y=5
x=$((x - y))
echo $x
A5
B105
Cx - y
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate arithmetic expression

    The expression x=$((x - y)) subtracts 5 from 10, resulting in 5.
  2. Step 2: Output the value of x

    Echo prints 5 as the result of the subtraction.
  3. Final Answer:

    5 -> Option A
  4. Quick Check:

    Arithmetic with $(( )) evaluates correctly [OK]
Quick Trick: Use $(( )) to perform arithmetic operations [OK]
Common Mistakes:
MISTAKES
  • Not using $(( )) for arithmetic
  • Concatenating strings instead of subtracting
  • Expecting variable names as output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes