I have read so many suggestions about, not putting your customization aka commands in ".profile" file. Rather, create a .bash_profile for yourself and add your alias and etc.
But,when I open the new terminal, if there is only .bash_profile, OS X is not exporting/sourcing the commands mentioned in it. I have to manually source the .bash_profile.
If I create .profile file, on opening a new terminal, all my commands in .profile are executed and will be available readily.
Could you please help me in understanding, how does it works? Also, when to use .bashrc/.profile/.bash_profile files.
Thanks!
Open Launchpad > Other > Terminal. Type in the following command to move the home directory and press Enter: cd ~/ Input the below touch command to create the bash_profile on Mac:touch . bash_profile.
View an installed configuration profile On your Mac, choose Apple menu > System Preferences, then click Profiles . If you haven't installed any configuration profiles, Profiles preferences isn't available. Select a profile in the Profiles list to view information about it.
Open/Edit .bash_profile file can be opened by using command line text editors or GUI text editors. The nano command line text editor can be used to open and edit . bash_profile. Alternatively, the GUI-based text editor of the MacOSX can be used with the following command.
According to the manual page that ships with OS X:
... it looks for
~/.bash_profile
,~/.bash_login
, and~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable. The--noprofile
option may be used when the shell is started to inhibit this behavior.
It should only read ~/.profile
as a last resort if neither ~/.bash_profile
nor ~/.bash_login
are readable.
On all of my OS X systems, I have my ~/.bash_profile
set to:
if [ -f ~/.bashrc ]; then source ~/.bashrc fi
It is highly recommended that you do this on OS X in order to get bash to read your ~/.bashrc
file like you would expect.
It's also possible that your terminal shell is defaulting to sh instead of bash. You can verify this first:
$ echo $SHELL /bin/tcsh
To change this to bash, you can go into your Terminal -> Preferences -> Startup tab, and change "Shell Opens With:" from "Default login shell" to Command and value "/bin/bash".
Alternately, you can change your default shell by executing the following command at the command prompt:
chsh -s bin/bash
After you do one of these, open a new shell window, and your .bash_profile should be sourced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With