Domanda

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'
È stato utile?

Soluzione 2

I got what I wanted by doing this:

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

vscode='Visual Studio Code'

batchelor=~/git/batcheloranator
iridium=~/git/iridium
chem=~/git/chemistry_stuff
 
 ~:    
 λ  open -a "$vscode"; echo $?
0

 ~:    
 λ  cd $iridium
 iridium:  (master)  
 λ  

Altri suggerimenti

$ alias --man
NAME
  alias - define or display aliases

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

DESCRIPTION
  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.

Example:

$ 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
/opt/local/bin
/opt/local/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Applications/VMware Fusion.app/Contents/Public
/Applications/Visual Studio Code.app/Contents/Resources/app/bin
/Users/mwilson/bin
/Users/mwilson/.local/bin
/Users/mwilson/Library/Python/3.9/bin
$ whence code
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'
$ 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a apple.stackexchange
scroll top