Bird
0
0

Which of the following is the correct way to create a local variable inside a Bash function?

easy📝 Syntax Q12 of 15
Bash Scripting - Variables
Which of the following is the correct way to create a local variable inside a Bash function?
AVAR=value
Bexport VAR=value
Clocal VAR=value
Dsetlocal VAR=value
Step-by-Step Solution
Solution:
  1. Step 1: Identify local variable syntax in Bash functions

    Inside a function, the keyword local declares a variable limited to that function.
  2. Step 2: Compare options

    export makes variables environment variables, setlocal is not a Bash command, and VAR=value without local is global or inherited.
  3. Final Answer:

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

    Use local inside functions for local variables [OK]
Quick Trick: Use 'local' keyword inside functions for local variables [OK]
Common Mistakes:
MISTAKES
  • Using export instead of local inside functions
  • Assuming VAR=value inside function is local
  • Using non-existent commands like setlocal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes