Bird
0
0

Identify the error in this Bash function:

medium📝 Debug Q6 of 15
Bash Scripting - Functions
Identify the error in this Bash function:
myfunc() {
  local 1var=100
  echo $1var
}
myfunc
AMissing semicolon after local declaration
BVariable name cannot start with a digit
Clocal keyword cannot be used inside functions
DEcho command syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check variable naming rules

    Variable names cannot start with digits in Bash.
  2. Step 2: Analyze code

    local 1var=100 is invalid due to starting digit.
  3. Step 3: Other options

    Semicolon not required; local is valid inside functions; echo syntax is correct.
  4. Final Answer:

    Variable name cannot start with a digit -> Option B
  5. Quick Check:

    Variable names must start with letter or underscore [OK]
Quick Trick: Variable names cannot begin with digits [OK]
Common Mistakes:
MISTAKES
  • Using invalid variable names
  • Thinking local can't be used in functions
  • Misunderstanding echo syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes