Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q6 of 15
Bash Scripting - User Input
Identify the error in this script snippet:
echo "Argument 1 is $1"
echo "Argument 2 is $2"
echo "Total args: $#"
Run as ./script.sh with no arguments.
ANo error; outputs empty $1 and $2
BScript crashes due to missing arguments
CSyntax error in echo statements
DIncorrect use of $# variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand behavior with no arguments

    $1 and $2 are empty strings if no arguments passed.
  2. Step 2: Check if script errors out

    Echoing empty variables is valid; no crash or syntax error occurs.
  3. Final Answer:

    No error; outputs empty $1 and $2 -> Option A
  4. Quick Check:

    Empty args print empty strings, no crash [OK]
Quick Trick: Empty args become empty strings, no crash [OK]
Common Mistakes:
MISTAKES
  • Expecting error on missing args
  • Confusing $# with argument values
  • Assuming syntax error in echo

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes