bashterminalalias.profile

Error when adding alias to .profile in mac


I have edited my .profile file on Mac, in order to create an alias in Terminal. I have added:

alias goto_test="cd /Library/WebServer/Documents"

I save .profile file and run:

source .profile

However, Terminal returns an error:

-bash: alias: /Library/WebServer/Documents: not found

What am I doing wrong?

.

Notes

When I execute cd /Library/WebServer/Documents in Terminal, the path works fine.

I have noticed that defining an alias with alias show_test="ls" throws an error because it seems to be trying to execute "ls" with quotation marks.

alias show_test=ls without quotation marks does work.

But, using alias goto_test=cd ~/ without quotation marks does not work because it is a multi-word command.


Solution

  • Disable smart quotes in OS X. Your ASCII double quotes are being replaced by fancy slanted Unicode quotes that bash doesn't recognize.

    Here's a reproduction of the problem:

    $ cat profile                                                                
    alias goto_test=“cd /Library/WebServer/Documents”                            
    
    $ source profile                                                             
    bash: alias: /Library/WebServer/Documents”: not found                        
    
    $ shellcheck profile                                                         
    In profile line 1:                                                           
    alias goto_test=“cd /Library/WebServer/Documents”                            
                    ^-- SC1015: This is a unicode double quote. 
                                Delete and retype it.
    
    $ cat -vE profile                                                            
    alias goto_test=M-bM-^@M-^\cd /Library/WebServer/DocumentsM-bM-^@M-^]$