QA
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→

More Linux Commands & SysAdmin Interview Questions

Beginner LevelLinux Commands & SysAdmin

How do Linux File Permissions (chmod, chown, chgrp) work in Octal and Symbolic notation?

Beginner LevelLinux Commands & SysAdmin

What is the Linux Filesystem Hierarchy Standard (/bin, /etc, /var, /usr, /opt, /tmp)?

Beginner LevelLinux Commands & SysAdmin

What are File Descriptors (0=stdin, 1=stdout, 2=stderr) and Redirection (>, >>, 2>&1)?