Need For User bash_profile File In Linux

Every user in Linux has a profile. The profile is a set of facilities or rights provided to the particular user accounts. For example, if root user has different profile, then you can compare with normal users. If you login with normal user, some of the commands will not be executed because the path of the command is not mentioned in variable (PATH). The .bashrc file will determine the behavior of interactive shells.

Example: 1

[[email protected] ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME

.bash_profile file contains default profile for root user.

The system admin or user can modify .bash_profile and .bashrc file to set up for their bash shell for various functions such as the prompt and path. The following example shows how to set variables in .bash_profile in linux.

Example: 2

[[email protected] ~]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
PATH=$PATH:$HOME/bin:.
BASH_ENV=$HOME/.bashrc
USERNAME="root"
export USERNAME BASH_ENV PATH

In the above example, the PATH= line sets the path to whatever is already there, plus $HOME/bin (in this case, /root/bin) and later on exported to the variables such as PATH, USERNAME and BASH_ENV.

Example: 3

The source command can be used to load any function file into the current shell script or a command prompt.

[[email protected] ~]#vi /home//.bash_profile

value="test"
export value

[[email protected] ~]#source /home//.bash_profile
#echo $value
test

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.