Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make OS X to read .bash_profile not .profile file

Tags:

bash

macos

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!

like image 614
cherryhitech Avatar asked Sep 12 '13 19:09

cherryhitech


People also ask

How do I open bash_profile in Mac?

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.

Where is the .profile file in Mac?

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.

How do I edit a .profile file on a Mac?

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.


2 Answers

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.

like image 191
Andon M. Coleman Avatar answered Sep 25 '22 21:09

Andon M. Coleman


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.

like image 24
Matt S Avatar answered Sep 24 '22 21:09

Matt S