Saturday, April 27, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 13088  / 3 Years ago, wed, october 20, 2021, 8:18:04

My .bash_profile is like below:



alias l='ls -l'
alias p='pwd'
alias sites='cd /home/caveman/sites'
alias time_card='cd /home/caveman/sites/time-card/time-card'
alias ping='ping google.com'
alias bash_profile='gedit /home/caveman/.bash_profile'
alias webroot='cd /var/www'


every time I log into my machine I need to run the source .bash_profile to make all the alias available.



Can you guys figure out where is the problem is?


More From » command-line

 Answers
5

The ~/.bash_profile is only read in login session.



Also, having a ~/.bash_profile prevents the sourcing of ~/.profile, that is the preferred file to use for login shell in the bash configuration for Ubuntu.



When you log in the Display Manager (I suppose GDM), the ~/.profile is read by default (I don't know if GDM follows bash rules and read ~/.bash_profile instead, if exists).



Even if ~/.bash_profile were read from GDM, aliases are not inherited, so
the shell you have in a graphics terminal (that is not a login shell) cannot see them.



The solution is: put your aliases in ~/.bashrc, and use aliases only for very simple things, otherwise use functions.



The file ~/.bashrc is read by non-login interactive shells, and is sourced in ~/.profile, so that its content is also available in login shells.


[#43420] Wednesday, October 20, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eballxeye

Total Points: 370
Total Questions: 91
Total Answers: 139

Location: Suriname
Member since Sat, Jan 1, 2022
2 Years ago
;