Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Using aliases in Terminal

Dear All,

I'm trying to add new alias to my terminal so I used the below commands


First I went to my bash_profile by using the commands

cd ~

nano .bash_profile


Then I added the below line at the end of the file and saved it & exit the file

alias htdocs="cd /Applications/mamp/htdocs"

After that I closed the terminal and opened it again to restart it, then I typed "htdocs" then pressed enter but still found the terminal informing me "-sh: htdocs: command not found "


Now I'm asking why the alias not working with me ?!!! , what I miss ?!!!


Thanks

MacBook Pro (Retina, 13-inch, Mid 2014), OS X Mavericks (10.9.5)

Posted on Feb 28, 2018 5:46 AM

Reply
Question marked as Best reply

Posted on Feb 28, 2018 6:13 AM

It has been years since I used MAMP, so I don't know if your path to htdocs is correct. Isn't MAMP capitalized?


When you update the ~/.bash_profile, or ~/.bashrc file, you either update your Bash session by quitting the Terminal and restarting it, or with the following command which updates your alias without quitting Terminal:


source ~/.bash_profile


Also, I use single, straight quotes on my alias target.

9 replies
Question marked as Best reply

Feb 28, 2018 6:13 AM in response to Astm Ali

It has been years since I used MAMP, so I don't know if your path to htdocs is correct. Isn't MAMP capitalized?


When you update the ~/.bash_profile, or ~/.bashrc file, you either update your Bash session by quitting the Terminal and restarting it, or with the following command which updates your alias without quitting Terminal:


source ~/.bash_profile


Also, I use single, straight quotes on my alias target.

Feb 28, 2018 6:32 AM in response to Astm Ali

That would imply that you did not quit Terminal and re-launch it after modifying the .bash_profile

Of that you have some funky Terminal preferences set that is preventing .bash_profile from being read by the shell when you start.


I'm assuming you are running the default shell 'bash'


If you are running a different shell, that also might explain it.

Mar 4, 2018 11:18 AM in response to Astm Ali

1 -- I put this line in the being of my .profile_bash

echo in ~/".bash_profile but claims to be $0 running under ${OSTYPE}"

I put similar lines in all my profiles.

here is what I see when I start a terminal session.


Last login: Sun Mar  4 14:02:13 on ttys000
in /etc/profile         but claims to be in -bash
in /etc/bashrc     claims to be in -bash
in /Users/mac/.bash_profile   but claims to be -bash running under darwin14
in /Users/mac/config/profile.bash     claims to be -bash
mac $


Yes, my .bash_profile calls config/profile.bash. The /etc/profile and /etc/bashrc are system stuff.


2 -- run the alias command to see what was aliased.


mac $ alias
alias abc='echo '\''ABCDEFHIJKLMNOPQRSTUVWXYZ ~!@#$%^&*()_+{}:"<>?'\'''
alias cd='cdir'
alias cp='cp -i'
alias df='df  -h '
alias dir='\ls -lh'


3 -- put an echo before and after your alias command.


4-- put the alias command alone "alias" after your aliasing to see if your command worked.


Doing this will help debug your system.


R

Mar 4, 2018 1:20 PM in response to Astm Ali

You are NOT running 'bash', so .bash_profile is not being invoked

"-sh: htdocs: command not found "

the -sh says you are running sh. If you were running bash it would say -bash: but it does not.


What does the following command say:

dscl . -read $HOME shell

If the output is

dsAttrTypeNative:shell: /bin/sh

then you need to use .profile


Or you need to change your shell to the default bash.


It is possible that the dscl command will say /bin/bash. If that is the case, then it is possible you have your Terminal -> Preferences -> General -> Shells to open with: (X) Command (complete path): /bin/sh

Mar 5, 2018 5:58 AM in response to Astm Ali

First I would like every one for helping me, It's working well now after I changed the alias to .profile as BobHarris saidto me

Some information to keep in the back of your mind.


By default macOS sets the default shell to bash. The fact that you are using sh means there has been some change made to your macOS setup. Whether you did this intentionally, or by accident, you should keep this in mind.


And the reason you should keep this in mind is that if you create a new account, or switch to a different Mac, you may find that in the new environment bash is now your shell, and assumptions you were making in your current environment are not working the same in the new environment.


And now that you have BOTH a .bash_profile _AND_ a .profile, you should know that if you magically switch back to bash, that when bash starts up it looks for one of the following 3 initialization files in the following order, and will use the first it finds, then ignore all the others

.bash_profile

.bash_login

.profile


I mention this, because if you end up back with bash in your current account, it will start using the .bash_profile you currently have, and ignore the .profile you may have built up. This will be confusing, so keep this bit of information in the back of your mind. Unless of course you delete the .bash_profile, then bash will also find your .profile.


Confusing, isn't it 😕

Using aliases in Terminal

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