Beginner LevelLinux Commands & SysAdmin
How do environment variables work using export, env, and printenv?
❓ Interview Prompt: Explain shell variables vs environment variables, export command, $PATH variable, and system persistence.
Environment variables store dynamic key-value pairs accessed by applications and shell sessions:
Concepts:
•
Local Variable: 'VAR="val"' (accessible ONLY in current shell process).
•
Environment Variable: 'export VAR="val"' (inherited by all child processes spawned in shell).
•
'$PATH': Colon-separated list of directories searched for executable commands.
•
Print Variables: 'printenv' or 'echo $VAR'.
Code Implementation Example
bash
# Display active system PATH directories
echo $PATH
# Export environment variable for child scripts
export NODE_ENV="production"
export PATH="$HOME/.local/bin:$PATH"
# List all active environment variables
printenv💡Exporting environment variables and updating system PATH.
🎯 Interview Key Takeaway
Use export to expose shell variables to child processes, and update $PATH to include custom executable directories.
#Environment Variables#export#PATH#Beginner
Back to all Linux Commands & SysAdmin Questions→