Overview - Environment variables vs local variables
What is it?
Environment variables and local variables are two types of variables used in bash scripting to store data. Local variables exist only inside the current shell or script, while environment variables are available to the current shell and any child processes it starts. This means environment variables can be accessed by other programs or scripts launched from the shell. Understanding the difference helps control data visibility and scope in scripts.
Why it matters
Without knowing the difference, you might accidentally expose sensitive data or fail to share important settings between scripts. Environment variables allow programs to share configuration easily, while local variables keep data private to avoid conflicts. Without environment variables, scripts would struggle to communicate or inherit settings, making automation and system management harder.
Where it fits
Before learning this, you should understand basic bash scripting and how variables work in general. After this, you can learn about exporting variables, shell scopes, and how to pass data between scripts or processes.