Need For User bash_profile File In Linux
Every user in Linux, has profile. Profile is set of facilities or rights giving to the particular user accounts. For example, root user has different profile if you compare with normal users. If you login with normal user, some the commands will not be executed, because path of the command is not mentioned in variable (PATH). The .bashrc file determine the behavior of interactive shells.
Example: 1
[root@localhost ~]# 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.
System admin or User can modify .bash_profile and .bashrc file to set up for their bash shell various functions such as the prompt, and path. In the following example show how to set variables in .bash_profile in linux
Example: 2
[root@localhost ~]# 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 above example: The PATH= line sets the path to whatever is already there, plus $HOME/bin (in this case, /root/bin), later on exported the variables such as PATH, USERNAME, BASH_ENV.
The source command can be used to load any functions file into the current shell script or a command prompt.
Example :
[root@localhost ~]#vi /home/
/.bash_profile value=”test”
export value[root@localhost ~]#source /home/
/.bash_profile
#echo $value
test
Category: Linux Administration
