Bird
0
0

What is the problem with this bash script snippet?

medium📝 Debug Q7 of 15
Bash Scripting - User Input
What is the problem with this bash script snippet?
#!/bin/bash
shift -2
echo "$1"
ANegative shift values are invalid and cause an error
BIt will shift arguments twice correctly
CIt will print the last argument
DIt will ignore the shift command
Step-by-Step Solution
Solution:
  1. Step 1: Check shift argument

    The shift command does not accept negative numbers.
  2. Step 2: Effect of negative argument

    Using shift -2 results in an error: "shift: negative shift count".
  3. Final Answer:

    Negative shift values are invalid and cause an error -> Option A
  4. Quick Check:

    Shift argument must be non-negative integer [OK]
Quick Trick: Shift argument cannot be negative [OK]
Common Mistakes:
MISTAKES
  • Using negative numbers with shift
  • Expecting shift to reverse arguments
  • Ignoring error messages from shift

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes