0
0
Bash Scriptingscripting~5 mins

Environment variables vs local variables in Bash Scripting - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a local variable in bash scripting?
A local variable is a variable defined inside a script or function that is only accessible within that script or function. It does not affect or get affected by the outside environment.
Click to reveal answer
beginner
What is an environment variable in bash scripting?
An environment variable is a variable that is available system-wide or to all child processes of the shell. It is used to pass information to programs and scripts.
Click to reveal answer
beginner
How do you create a local variable in bash?
Simply assign a value without the export keyword, for example: myvar="hello". This variable stays local to the current shell or script.
Click to reveal answer
beginner
How do you create an environment variable in bash?
Use the export command before the variable, like export MYVAR="hello". This makes the variable available to child processes.
Click to reveal answer
intermediate
Why use environment variables instead of local variables?
Environment variables let you share data with other programs or scripts started from your shell. Local variables are only for temporary use inside one script or shell session.
Click to reveal answer
Which command makes a variable available to child processes in bash?
Aexport
Blocal
Cset
Ddeclare
What happens if you define a variable without 'export' in bash?
AIt becomes an environment variable
BIt is available to all users
CIt is local to the current shell or script
DIt is deleted immediately
Which variable type is accessible by all programs started from the shell?
ALocal variable
BEnvironment variable
CTemporary variable
DGlobal variable
How do you remove an environment variable in bash?
Aunset variable_name
Bdelete variable_name
Cremove variable_name
Dclear variable_name
Which of these is true about local variables in bash?
AThey are shared with all users
BThey persist after the shell closes
CThey require the export command
DThey are only available inside the current shell or script
Explain the difference between environment variables and local variables in bash scripting.
Think about where each variable can be accessed.
You got /4 concepts.
    Describe how to create and use an environment variable in a bash script.
    Focus on the export command and its effect.
    You got /4 concepts.