I have some aliases in my ~/.bashrc and ~/.bash_profile (I tried with and without .bash_profile), they were both sourced.

alias ll=‘ls -l’ 
alias al=‘ls -ahl’

alias iridium=“~/git/iridium”
alias vscode=“Visual Studio Code” 

On Ubuntu, centos and fedora these would work fine.

Even on windows git bash I had long aliases to open games with the huge steam path.

But on big sur:

only the ls aliases work.

is there a reason for this?

I’m also sourcing these files from /etc/bashrc

Look at it in action:

 λ  cat ~/.bash_profile 
alias ll='ls -l'
alias al='ls -ahl'

alias vscode='Visual Studio Code'

alias batchelor="~/git/batcheloranator"
alias iridium="~/git/iridium"
alias chem="~/git/chemistry_stuff"
 chemistry_stuff:  (master)  
 λ  . ~/.bash_profile 
 chemistry_stuff:  (master)  
 λ  cd iridium
bash: cd: iridium: No such file or directory
 chemistry_stuff:  (master)  
 λ  cd chem
bash: cd: chem: No such file or directory
 chemistry_stuff:  (master)  
 λ  open -a vscode
Unable to find application named 'vscode'

2 Answers 2

$ alias --man
  alias - define or display aliases

  alias [ options ] [name[=value]...]

  alias creates or redefines alias definitions or writes the existing alias definitions to standard output. An alias
  definitions provides a string value that will replace a command name when the command is read. Alias names can
  contain any printable character which is not special to the shell. If an alias value ends in a space or tab, then the
  word following the command name the alias replaces is also checked to see whether it is an alias.

If you want your vscode alias to work, you need to do something like:

alias vscode='"visual studio code"'

So that the shell doesn't perform word-splitting on the string.


$ alias vscode='visual studio code'
$ vscode
ksh: visual: not found               <= shell word-splitting
$ alias vscode='"visual studio code"'
$ vscode
ksh: visual studio code: not found   <= shell not word-splitting

But what you really should do is follow VS Code's installation instructions for macOS, add /Applications/Visual Studio Code.app/Contents/Resources/app/bin to your path, and run code to start it.

$ path
/Applications/VMware Fusion.app/Contents/Public
/Applications/Visual Studio Code.app/Contents/Resources/app/bin
$ whence code
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'

I got what I wanted by doing this:

 λ  cat .bash_profile 
alias ll='ls -l'
alias al='ls -ahl'

vscode='Visual Studio Code'

 λ  open -a "$vscode"; echo $?

 λ  cd $iridium
 iridium:  (master)  
  • 1
    It appears you were confusing aliases (which hold executable commands, and must occur where a command name would normally be) and variables (which hold data, and must be expanded with $). See my answer here for more details. Jun 1, 2021 at 0:10

You must log in to answer this question.

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