The shell login scripts are the script that launch automatically after a login shell and permit to store permanently the values of environment variables.
Login Script By Shell
You can found them in two directory:
- in the home user (~) for a user scope
- in the /etc/ directory for a system scope. The /etc/ files contains system wide environment stuff and startup programs. All customization that you put in this file will apply for the entire environment variable on your system.
The login script mechanisms depends of the shell type.
- To determine your type of shell, refer to this article : Linux - Shell
- To get a complete view of all shell configuration files → Configuration files for shells
|Scope||Shell||Script or directory to modify|
|User||Bourne or Korn shell||~/.profile|
|User||C shell (csh)||~/.login|
|Global (All users except root)||Bash||/etc/profile.d|
Bash - The /etc/profile is the main entry point and call all custom script in the directory (/etc/profile.d). Add your global configuration in this directory. Example:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")
How changes can take effect immediately?
You can then make the changes to .bash_profile take effect immediately by typing the following command:
How to edit it ?
To edit the bash_profile :
- change to your home directory (ie: /home/myname)
- edit the file. Example with gedit.
- Add a line with your environment variable. Example for the PATH
Note the fullstop before 'bash'. This '.' makes it a hidden file