Environment Variables & Startup Files

Environment Variables

  • The shell stores information in the environment variables.

  • Each shell has its own values for these variables.

printenv

printenv
# Prints name and value pairs for all the environment variables
# VARIABLE_NAME=VALUE

printenv | grep PATH
  • SHELL - user's shell is bash

  • PWD - current working directory

  • HOME - home directory for the current user

  • PATH - list of the directories searched in order, to find commands to be executed.

    • Current working directory can be put first in this path, easier to execute current working directory programs but can be used for attacks.

There are two types of environment variables: global and local.

Global

  • Global variables can be accessed by anything executed in that shell = Environment Variables

export / unset

Local

  • Local variables are valid only for the current shell (and not for sub-shells) = Shell Variables

Startup files

  • When starting a new bash shell, the shell is configured using startup files.

  • Interactive non-login shell - the type of shell opened by the Terminal

  • alias name='COMMAND_VALUE' - the alias uses the entire command enclosed in single quotes

  • After adding an alias, a new shell must be created to make the alias work, or use the source .bashrc command in the same shell.

  • Using a shell other than bash, the startup file name will be different.


Last updated

Was this helpful?