Описание тега .bash-profile

A (typically short) shell script, executed when a bash user logs on.

~/.bash_profile is a script executed when a bash user logs on. The ~/.bash_profile only gets executed within a login shell unlike ~/.bashrc which gets executed when you run bash using an interactive shell.

Login Shells (.bash_profile)

A login shell is a bash shell that is started with - or --login.

Examples

  • sudo su -
  • bash --login
  • ssh user@host

When bash starts as a login shell the following files are executed in this order:

  1. /etc/profile
  2. ~/.bash_profile
  3. ~/.bash_login
  4. ~/.profile

Setting up a bash_profile

Reload bash_profile after making changes

source ~/.bash_profile

Syntax

The following characters can be used in defining PS1 and PS2.

\t - time
\d - date
\n - newline
\s - Shell name
\W - The current working directory
\w - The full path of the current working directory.
\u - The user name
\h - Hostname
\# - The command number of this command.
\! - The history number of the current command

Further Reading: