Bird
0
0

Identify the error in this script snippet: ```bash function example() { local VAR=123 export VAR } example ``` What will happen when running this script?

medium📝 Debug Q6 of 15
Bash Scripting - Variables
Identify the error in this script snippet: ```bash function example() { local VAR=123 export VAR } example ``` What will happen when running this script?
AVAR is local and not exported outside the function
BSyntax error due to exporting a local variable
CVAR is exported and available outside the function
DVAR is global and exported
Step-by-Step Solution
Solution:
  1. Step 1: Understand local and export interaction

    Declaring 'local VAR=123' limits VAR to the function scope. Exporting it inside the function exports it only in that shell instance.
  2. Step 2: Check effect outside function

    After function ends, local VAR is destroyed. Export does not make it available outside the function's shell environment.
  3. Final Answer:

    VAR is local and not exported outside the function -> Option A
  4. Quick Check:

    Local variables cannot be exported outside function scope [OK]
Quick Trick: Exporting local vars inside function doesn't export globally [OK]
Common Mistakes:
MISTAKES
  • Expecting exported local variable to persist outside function
  • Thinking export causes syntax error here
  • Confusing local and global scopes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes