|
|
|
Environment variables are key-value pairs that configure how programs behave. They’re inherited by child processes. |
|
|
Access environment variables with $ prefix: |
|
|
Check if a variable is set: |
|
|
Set a shell variable (not exported): |
|
|
Export makes it available to child processes: |
|
|
Check if it’s exported by running a subshell: |
|
|
Set and export in one line: |
|
|
Common environment variables: |
|
|
Modify PATH temporarily: |
|
|
Set variable for a single command: |
|
|
Unset a variable: |
|
|
Use |
|
|
Use |
|
|
Clear environment and run with specific vars: |
|
|
Default values for variables: |
|
|
Export all variables automatically (not recommended): |
|
|
Check if command exists in PATH: |
|
|
Configuration file pattern: |
|
|
Bash
Bash provides additional features |
|
|
Read-only export: |
|
|
List all exported variables: |
|
|
Check if variable is exported: |
|
|
Security: Don’t put secrets in environment variables that might be logged. Use files with restricted permissions. |
|