In .profile, why is alias not working?

Recently (since upgrading to Mavericks??), several alias commands in ~/.profile are not working after I start Terminal (although numerous path settings set up there are working as expected). For example, ~/.profile includes:


alias mysqlctl='sudo /usr/local/mysql/support-files/mysql.server'

alias mysqlstart='mysqlctl start'


But after I start Terminal and execute


mysqlstart


I get error:

bash: mysqlstart: command not found


I know that something peculiar is going on because when I attempt to exit the (one and only) running Terminal session with command exit I just see an echoed response


exit


but can quit Terminal by executing the same exit command again.


Moreover, if in Terminal I execute


source ~/.profile


then the aliases work as expected.


I did try the ruse I found somwhere of including before any of the other alias lines in .profile the command alias sudo='sudo ' but that doesn't fix the problem.


I thought perhaps some other startup file is being read and hence commands in ~/.profile are therefore not being executed, but I find no such: I have no

~/.bashrc or ~/.bash_profile or ~/.login file. (And Terminal is set to use the default login shell, which is bash.


What could be wrong and how can it be fixed?

iMac, OS X Mavericks (10.9), 3.4GHz Corei7, 16GB, SSD + 2T HD

Posted on Feb 8, 2014 9:41 PM

Reply
18 replies

Feb 9, 2014 1:35 AM in response to murrayE

It sounds like bash is not accessing your .profile when logging in via terminal.


You could try renaming your .profile to .bash_profile, or better still, create .bash_profile and add one line with ~/.profile to pick up the aliases.

Feb 9, 2014 7:59 AM in response to Community User

vonkempnz wrote:


It sounds like bash is not accessing your .profile when logging in via terminal.


You could try renaming your .profile to .bash_profile, or better still, create .bash_profile and add one line with ~/.profile to pick up the aliases.

How could it be that bash is not accessing my ~/.profile, given that all the additions to PATH that I've set in ~/.profile are recognized, as I see if I execute "echo $PATH" ? And given that the custom prompt exported from ~/.profile is also appearing?


One further peculiarity I had not seen before this problem arose: when I open Terminal, I see that expected prompt followed by "bash" (no quotes) on the first line and then a new line just with my prompt/

Feb 9, 2014 8:09 AM in response to murrayE

murrayE wrote:


vonkempnz wrote:


It sounds like bash is not accessing your .profile when logging in via terminal.


You could try renaming your .profile to .bash_profile, or better still, create .bash_profile and add one line with ~/.profile to pick up the aliases.

How could it be that bash is not accessing my ~/.profile, given that all the additions to PATH that I've set in ~/.profile are recognized, as I see if I execute "echo $PATH" ? And given that the custom prompt exported from ~/.profile is also appearing?


One further peculiarity I had not seen before this problem arose: when I open Terminal, I see that expected prompt followed by "bash" (no quotes) on the first line and then a new line just with my prompt/

Sounds like something inside your profile is calling bash again. So, you are running bash inside another bash shell.

Feb 9, 2014 8:29 AM in response to Barney-15E

I don't see anything in my ~/.profile that could be calling bash again. Here's the whole file (with commented-out lines omitted):


# Modify prompt:

export PS1="[\u@\h:\w]$ "


# MacPorts Installer addition: adding an appropriate PATH variable for use with MacPorts.

export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/apache2/bin:$PATH


export CLASSPATH=$CLASSPATH:/Volumes/MacHD/Users/murray/Library/texmf/texhyphj


# to allow GTK+Quartz

export CPPFLAGS="-I/opt/local/include $CPPFLAGS"

export LDFLAGS="-L/opt/local/lib $LDFLAGS"


# Setting PATH for TeX binaries

export PATH=/usr/texbin:$PATH


# Setting PATH for Python 3.3

PATH="${PATH}:/Library/Frameworks/Python.framework/Versions/3.3/bin"

export PATH


# Setting PATH for Python 2.7

PATH="${PATH}:/Library/Frameworks/Python.framework/Versions/2.7/bin"

export PATH


# added by Anaconda 1.7.0 installer

export PATH="$PATH:/Volumes/MacHD/Applications/Programming/Python/anaconda/bin"


export PATH=$PATH:"/Volumes/MacHD/Users/murray/Library/Application Support/GoodSync"


export PATH="$PATH:/Volumes/MacHD/Users/murray/bin"


export PATH=$PATH:/Volumes/MacHD/Applications/Math/Singular/3-1-6/ix86Mac-darwin


alias tomcat7start='/Library/Tomcat/bin/startup.sh'

alias tomcat7stop='/Library/Tomcat/bin/shutdown.sh'


# Set apachectl alias for MacPorts apache2

alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'

alias apachestart='sudo /opt/local/apache2/bin/apachectl -k start'

alias apachestop='sudo /opt/local/apache2/bin/apachectl -k stop'

alias apacherestart='sudo /opt/local/apache2/bin/apachectl restart'


# Set aliases for native MySQL from dev.mysql.com

alias mysqlclient='/usr/local/mysql/bin/mysql'

alias mysqladmin='/usr/local/mysql/bin/mysqladmin'

export PATH=/usr/local/mysql/bin:$PATH

alias mysqlctl='sudo /usr/local/mysql/support-files/mysql.server'

alias mysqlstart='mysqlctl start'

alias mysqlstop='mysqlctl stop'

alias mysqlstatus='ps aux | grep mysql | grep -v grep'

Feb 9, 2014 8:35 AM in response to murrayE

From the sh(1) man page:

When  bash is invoked as an interactive login shell, or as a non-inter-
active shell with the --login option, it first reads and executes  com-
mands  from  the file /etc/profile, if that file exists.  After reading
that file, 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.

Feb 9, 2014 9:16 AM in response to murrayE

I tried the method recommended at http://stackoverflow.com/questions/18773051/how-to-make-os-x-to-read-bash-profil e-not-profile-file, namely, to move all the commands formerly in ~/.profile into ~/.bashrc and then to create ~/.bash_profile consisting of lines:


if [ -f ~/.bashrc ]; then

source ~/.bashrc

fi


(And of course delete ~/.profile).


That does now allow my alias commands (formerly in ~/.profile and now in ~/.bashrc) to work in Terminal.


However, now executing in Terminal echo $PATH gives my entire path (as defined in ~/.bashrc) twice -- in a rather strange order of duplication:


/usr/local/mysql/bin

/usr/texbin

/opt/local/bin

/opt/local/sbin

/opt/local/apache2/bin

/usr/local/mysql/bin

/usr/texbin

/opt/local/bin

/opt/local/sbin

/opt/local/apache2/bin

/usr/bin

/bin

/usr/sbin

/sbin

/usr/local/bin

/opt/X11/bin

/usr/local/MacGPG2/bin

/usr/texbin

/Library/Frameworks/Python.framework/Versions/3.3/bin

/Library/Frameworks/Python.framework/Versions/2.7/bin

/Volumes/MacHD/Applications/Programming/Python/anaconda/bin

/Volumes/MacHD/Users/murray/Library/Application Support/GoodSync

/Volumes/MacHD/Users/murray/bin

/Volumes/MacHD/Applications/Math/Singular/3-1-6/ix86Mac-darwin

/Library/Frameworks/Python.framework/Versions/3.3/bin

/Library/Frameworks/Python.framework/Versions/2.7/bin

/Volumes/MacHD/Applications/Programming/Python/anaconda/bin

/Volumes/MacHD/Users/murray/Library/Application Support/GoodSync

/Volumes/MacHD/Users/murray/bin

/Volumes/MacHD/Applications/Math/Singular/3-1-6/ix86Mac-darwin


So something is still wrong!


Feb 9, 2014 9:28 AM in response to Linc Davis

Linc Davis wrote:


From the sh(1) man page:

When  bash is invoked as an interactive login shell, or as a non-inter- active shell with the --login option, it first reads and executes  com- mands  from  the file /etc/profile, if that file exists.  After reading that file, 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.

Yes, I know that. That's why I had made sure I had no `~/.bash_profile` or `~/.bash_login`. And in any case it doesn't explain what was wrong, since while my `alias` settings in `~/.profile` were not being effected, all my path settings in `~/.profile` *were* being effected.


(That's before I used the `~/.bashrc` plus `~/.bash_profile` combination (with no `~/.profile`) described in other posts to this thread.)

Feb 9, 2014 10:06 AM in response to murrayE

murrayE wrote:


I tried the method recommended at http://stackoverflow.com/questions/18773051/how-to-make-os-x-to-read-bash-profil e-not-profile-file, namely, to move all the commands formerly in ~/.profile into ~/.bashrc and then to create ~/.bash_profile consisting of lines:


if [ -f ~/.bashrc ]; then

source ~/.bashrc

fi


(And of course delete ~/.profile).


That does now allow my alias commands (formerly in ~/.profile and now in ~/.bashrc) to work in Terminal.


However, now executing in Terminal echo $PATH gives my entire path (as defined in ~/.bashrc) twice...


So something is still wrong!


I think I may understand why I'm seeing PATH entries duplicated when I execute


echo $PATH


At login, OS X reads in ~/.bash_profile and hence ~/.bashrc (which establishes all my path settings there). Then when I open Terminal, it reads all those path settings again, which get appended to my settings already made.


In fact, I think that's why in the first place I put all my settings into ~/.profile rather than into ~/.bash_profile or~/.bashrc. And that used to work, including for the aliases set in ~/.profile. And so there's still no explanation I see for why the aliases stopped working!


Perhaps I shouldn't worry about the duplicated entries in PATH??


But still something else is wrong: if in Terminal I execute


exit


then I just get back an echo of that at a new prompt, and only typing and executing exit at the next prompt will actually produce the expected


logout


[Process completed]


What used to work just fine stopped working!

Feb 9, 2014 10:09 AM in response to Frank Caggiano

Frank Caggiano wrote:


If you enter alias in the terminal, what shows? How are the alias'a displayed?

Now that I moved all the alias settings into ~/.bashrc, they all show, as follows:


alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'

alias apacherestart='sudo /opt/local/apache2/bin/apachectl restart'

alias apachestart='sudo /opt/local/apache2/bin/apachectl -k start'

alias apachestop='sudo /opt/local/apache2/bin/apachectl -k stop'

alias mysqladmin='/usr/local/mysql/bin/mysqladmin'

alias mysqlclient='/usr/local/mysql/bin/mysql'

alias mysqlctl='sudo /usr/local/mysql/support-files/mysql.server'

alias mysqlstart='mysqlctl start'

alias mysqlstatus='ps aux | grep mysql | grep -v grep'

alias mysqlstop='mysqlctl stop'

alias tomcat7start='/Library/Tomcat/bin/startup.sh'

alias tomcat7stop='/Library/Tomcat/bin/shutdown.sh'


I'll revert to my original configuration, with them in ~/.profile, and no ~/.bashrc or ~/.bash_profile, and answer this again later.

Feb 9, 2014 10:49 AM in response to Frank Caggiano

OK, I'm now back with all my path and alias settings in ~/.profile and with no files ~/.bash_profile or ~/.bashrc. I logged out from OS X and back in. In Terminal, echo $PATH shows that all the path settings from ~/.profile have been made. Yet once again, as at the start, the aliases don't work. Thus (notice the strange echo-back of both "set -x: and, later, "exit", which doesn't produce the expected logout[Process completed]).


$ set -x

+ set -x

$ alias

+ alias

$ mysqlstart

+ mysqlstart

bash: mysqlstart: command not found

$ exit

+ exit

exit

$


But wait, it's even stranger than that! Now, after that exit, if I execute alias I see all my aliases -- and they work!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

In .profile, why is alias not working?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.