Variables
Enumerate
env
Displays environment variables.
printenv
Similar to env, also lists environment variables.
set
Lists shell variables and functions (bash-specific).
declare -p
Lists shell variables with their attributes (bash-specific).
export
Displays exported variables (visible to child processes).
Modify
export VAR_NAME=VALUE
Sets an environment variable for the current shell and child processes.
VAR_NAME=VALUE
Sets a variable for the current shell only (not inherited by child processes).
Sourcing files
Use source filename
or . filename
to import variables from a file into the current shell environment.
Environment Variables
PATH
Contains a colon-separated list of directories where executable files are located.
HOME
Stores the absolute path to the user's home directory.
USER (or LOGNAME)
Contains the username of the currently logged-in user.
SHELL
Specifies the default shell for the user.
PS1
Defines the primary shell prompt.
PS2
Defines the secondary prompt used when entering multi-line commands.
PS3
Specifies the prompt for the select loop in shell scripts.
PS4
Specifies the prompt for debugging shell scripts with the -x option.
PWD
Holds the current working directory.
OLDPWD
Contains the previous working directory.
TZ
Specifies the system's timezone.
IFS
Defines the Internal Field Separator, which is used to separate words in shell commands.
TERM
Specifies the type of terminal or terminal emulator being used.
EDITOR
Sets the default text editor used by some command-line utilities.
VISUAL
Specifies the default visual (graphical) editor used by some utilities.
LANG
Specifies the default system language and localization settings.
LC_*
A family of variables used for localization and character encoding settings.
Points to the location of the user's mailbox or mail spool file.
MAILCHECK
Specifies how often to check for new mail.
MAILPATH
Contains a list of files to check for new mail.
LD_LIBRARY_PATH
Lists directories where the dynamic linker/loader searches for shared libraries.
LD_PRELOAD
Specifies shared libraries to be loaded before all others when a program is run.
MANPATH
Defines the path to the directory containing manual pages (man pages).
File Locations
Environment Variables
Often set in startup scripts like .bashrc, .bash_profile, or system-wide configuration files.
User Environment Variables
Typically set in the user's shell initialization files (e.g., .bashrc, .bash_profile, .profile) or by using the export command in the shell.
System Environment Variables
System-wide environment variables can be set in system-wide initialization scripts, such as /etc/environment on some Linux distributions.
Global System Variables
Some system-level variables are stored in system configuration files or directories. These can include variables related to network configuration, system parameters, and system behavior. These variables are often stored in files located in /etc or other system directories.
User-Specific Configuration Files
User-specific configuration files may store variables related to a specific user's environment and preferences. For example, the ~/.bashrc or ~/.bash_profile files can contain user-specific variables and configurations.
Last updated
Was this helpful?