Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q14 of 15
Bash Scripting - User Input
Identify the error in this script snippet:
shift 3
echo $1
Assuming the script is run with only two arguments.
AError: shift 3 tries to shift more arguments than exist, causing an error.
BNo error; it prints the first argument unchanged.
CError: shift requires a negative number to work.
DNo error; it prints the third argument.
Step-by-Step Solution
Solution:
  1. Step 1: Check number of arguments

    The script has only two arguments but tries to shift by three.
  2. Step 2: Understand shift behavior on excess shift

    Shifting more than available arguments causes an error or empties all arguments.
  3. Final Answer:

    Error: shift 3 tries to shift more arguments than exist, causing an error. -> Option A
  4. Quick Check:

    Shifting beyond argument count causes error [OK]
Quick Trick: Don't shift more than available arguments to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Assuming shift works with negative numbers
  • Ignoring argument count before shifting
  • Expecting shift to print unchanged arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes