7. Environment Variables

7.1. Paths

  • /etc/environment

  • /etc/profile

  • /etc/bashrc

  • ~/.bashrc

  • ~/.profile

  • /etc/alternatives/

7.2. Variables

  • $HOME - User Home Directory

  • $HOSTNAME - Hostname

  • $IFS - Inter Field Separator

  • $LANG - System Language

  • $PATH - Executable Search Path

  • $PS1 - Prompt

  • $PWD - Present Working Directory

  • $SHELL - Current Shell

  • $TERM - Current Terminal (character mapping)

  • $UID - User ID

  • $UMASK - Permission mask for new files

  • $USER - Username

  • $LANG -

  • $LS_COLORS -

  • $_ -

7.3. PS1

../../_images/bash-colors.png

Figure 7.3. Bash colors

# Colors
red='\[\033[00;31m\]'
green='\[\033[00;32m\]'
blue='\[\033[00;36m\]'
white='\[\033[00;39m\]'

# User Prompt
[ $UID != 0 ] && export PS1="\n${green}$ ${white}"

# Root Prompt
[ $UID == 0 ] && export PS1="\n${red}# ${white}"

# Remote Prompt
[ $SSH_CONNECTION ] && export PS1="\n${green}\h $ ${white}"

7.4. Commands

Table 7.1. Env

Command

Type

Description

env

Show all environmental variables

env

run a program in a modified environment

update-alternatives

maintain symbolic links determining default commands

export

Set environment variable