Bird
0
0

What will be the output of this command?

medium📝 Command Output Q5 of 15
Linux CLI - Text Processing
What will be the output of this command?
echo "apple 10 red" | awk '{print $2+$3}'
A10
BError
C0
D10red
Step-by-Step Solution
Solution:
  1. Step 1: Understand field values and operation

    $2 is "10" (number), $3 is "red" (string). Adding number + string in awk treats string as 0.
  2. Step 2: Calculate result of addition

    10 + 0 = 10, but since $3 is non-numeric, awk treats it as 0, so output is 10 + 0 = 10.
  3. Step 3: Test actual behavior

    Awk treats non-numeric string as 0 in numeric context, so output is 10 + 0 = 10.
  4. Final Answer:

    10 -> Option A
  5. Quick Check:

    Non-numeric fields treated as 0 in arithmetic [OK]
Quick Trick: Non-numeric fields become 0 in arithmetic operations [OK]
Common Mistakes:
  • Concatenating fields instead of adding
  • Expecting error on string addition
  • Ignoring numeric conversion rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes