Skip to content

Latest commit

 

History

History
52 lines (43 loc) · 1.7 KB

File metadata and controls

52 lines (43 loc) · 1.7 KB

Chapter 11

The shell stores two basic types of data in the environment, environment variables and shell variables.

To see env var

$ printenv | less
OR
$ printenv USER
himanshu
OR
$ echo $USER
himanshu

One element of the environment that neither set nor printenv displays is aliases.

$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

Startup Files For Login Shell Sessions

  • /etc/profile: A global configuration script that applies to all users.
  • ~/.bash_profile: A user's personal startup file. Can be used to extend or override settings in the global configuration script.
  • ~/.bash_login: If ~/.bash_profile is not found, bash attempts to read this script.
  • ~/.profile: If neither ~/.bash_profile nor ~/.bash_login is found, bash attempts to read this file. This is the default in Debian-based distributions, such as Ubuntu.

Startup Files For Non-Login Shell Sessions

  • /etc/bash.bashrc: A global configuration script that applies to all users.
  • ~/.bashrc: A user's personal startup file. Can be used to extend or override settings in the global configuration script.

Export Env Var

$ export ME="hp"
$ echo $ME
hp

Use a text editor to create/edit a file

$ gedit some_file

As a general rule, to add directories to your PATH, or define additional environment variables, place those changes in .bash_profile. cp will overwrite existing files silently.