I create an alias behavior

alias chrome="open -a 'Google Chrome'"
chrome foo.html

Nevertheless, It refuses to work when I restart the terminal.

$ chrome foo.html
-bash: chrome: command not found

As a solution, I place the command to ~/.bash_profile

# Add to ~/.bash_profile
# shortcut for chrome
alias chrome="open -a 'Google Chrome'"

Again, it report similar error

$ chrome foo.html
-bash: chrome: command not found

How to solve such a problem?

  • 1
    Did you try adding it to .bashrc? – nohillside Apr 1 '18 at 5:23
  • What's the output of echo $PATH? Note that you could also just make it into an executable and throw it in your $HOME/bin/ – njboot Apr 1 '18 at 5:28
  • Try using the bundle identifier instead of the app name- alias chrome='open -b com.google.Chrome' – fd0 Apr 1 '18 at 6:52
  • What is the output of echo $SHELL? If you're using bash, adding the alias to .profile or .bash_profile should work. – ivicaa Apr 1 '18 at 21:24
  • Add it to the files ~/.profile and ~/.bashrc. You're using the Apple version of bash, which sources the configuration files differently than GNU's bash releases. I can't remembe correctly but I think Apple's version only reads ~/.bashrc at startup so you need bashrc to source ~/.bash_profile to source other files at startup. – Jahhein Apr 1 '18 at 21:33

You need to relogin( to apply changes from .bashrc) or do

source ~/.bashrc

which do the same work for your needs

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .