MM

CentOS 7 Shell and Environment Variables Notes

Understanding the CentOS 7 Shell and Environment Variables

  • Shell Definition:

    • The shell is a command interpreter that executes commands in a terminal session.

    • Default shell in CentOS 7 is bash (Bourne Again SHell), an enhanced version of the original UNIX Bourne shell.

  • Environment Variables:

    • Similar to Windows 10, CentOS 7 supports the use of environment variables which can be read, changed, or added.

    • Example command syntax to set an environment variable temporarily:

    • VARNAME="ABC Company"

    • This variable VARNAME will store "ABC Company" until the user logs out or exits the shell session.

    • To make other programs aware of this variable, execute:

    • export VARNAME

    • To remove a variable, use:

    • unset VARNAME

Common Environment Variables in CentOS 7

Predefined Bourne Shell Environment Variables
  • Table of Variables:

    • Variable | Description

    • SHELL: Returns the location where applications store data by default.

    • PS1: The primary prompt string.

    • PATH: A list of directories where the shell looks for commands, separated by colons.

    • HOME: The current user's home directory, which is the default for the cd command.

Additional Bourne Shell Environment Variables
  • Table of Additional Variables:

    • Variable | Description

    • BASH: Full path name used to execute the current instance of bash.

    • BASH_VERSION: Version number of the current instance of bash.

    • EDITOR: Name of the default text editor.

    • HISTFILE: File where command history is stored; default is ~/.bash_history.

    • HISTFILESIZE: Maximum number of lines in the history file; defaults to 500. When set, it truncates older entries if necessary to stay at this size.

    • HISTSIZE: Maximum number of commands remembered in the history list; defaults to 500.

    • HOSTNAME: Name of the current host.

    • LINES: Used by built-in commands to determine column length for printing selection lists.

    • PWD: Current working directory as designated by the cd command.

    • RANDOM: Generates a random integer between 0 and 32767 whenever referenced; assigning a value seeds the random number generator.

    • SECONDS: Represents the number of seconds since the shell was started.

    • UID: Numeric real user ID of the current user; this variable is read-only.