Friday, 29 May 2020

.bash_profile, .bash_rc, .profile

Login shell vs Non login shell

Login Shell :
SSH


Non login Shell :
Login into graphic GUI(MAC), open up terminal






For Login Shell :

system checks .bash_profile and .bash_login first it they do not exist, system reads .profile

Rules :
Some things from my own .bashrc (as an example):
  • Set $PS1
  • Enable special tab completion rules
  • Set shell options by running shopt
  • Set up command aliases
From my .bash_profile:
  • Source .bashrc
  • Add directories to $PATH
  • Run ssh-agent



Non login shell:
does not read .bash_profile or .profile
but it can always be manual run 
  1. Because terminals don't usually run login shells by default. They also usually have options to run login shells, which do source .profile.
  2. To control the behaviour of login shells.
  3. Depends on the shell. For bash, see the set of startup files.
  4. Not in some sense (updating login records, for example).
  5. If you have a folder called bin in $HOME, the default .profile for Ubuntu does add it to your PATH. Since .profile is sourced at login (even with a GUI login), it should be part of your PATH for non-login shells started after a re-login. It isn't wrong if a directory appears twice in PATH, see this U&L question for details.



source vs sh
sh foo.sh runs the script within the context of a new sh shell, which on many OSes is not even Bash (which may be one reason the script doesn't work). source is a bash-only built-in command. That means when you call source , there is no executable like /bin/source or so.

source ~/.bash_profile or . ~/.bash_profile

sh bla.sh or ./ bla.sh

No comments:

Post a Comment