Bird
0
0

Which of the following is the correct syntax to declare a local variable inside a Bash function?

easy📝 Syntax Q3 of 15
Bash Scripting - Variables
Which of the following is the correct syntax to declare a local variable inside a Bash function?
Amyvar=value
Bexport myvar=value
Clocal myvar=value
Dset myvar=value
Step-by-Step Solution
Solution:
  1. Step 1: Recall local variable syntax in functions

    Inside a Bash function, the 'local' keyword declares a variable limited to that function's scope.
  2. Step 2: Verify other options

    'export' makes variables environment variables; plain assignment is global or shell-local; 'set' is unrelated.
  3. Final Answer:

    local myvar=value -> Option C
  4. Quick Check:

    Use 'local' keyword inside functions [OK]
Quick Trick: Use 'local' inside functions for local variables [OK]
Common Mistakes:
MISTAKES
  • Using 'local' outside functions
  • Confusing 'export' with 'local'
  • Omitting 'local' inside functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes