macoszshzsh-alias

Create shell alias with semi-colon character


I've noticed that I have a tendency to mistype ls as ;s, so I decided that I should just create an alias so that instead of throwing an error, it just runs the command I mean.

However, knowing that the semi-colon character has a meaning in shell scripts/commands, is there any way to allow me to create an alias with that the semi-colon key? I've tried the following to no avail:

alias ;s=ls
alias ";s"=ls
alias \;=ls

Is it possible to use the semi-colon as a character in a shell alias? And how do I do so in ZSH?


Solution

  • For the record, here are the command definitions, but, again, they can only be invoked quoted.

    Function (works in zsh only; place in an initialization file such as ~/.zshrc):

     ';s'() { ls "$@" }
    

    Executable script ;s (works in dash, bash, ksh and zsh; place in a directory in your $PATH):

     #!/bin/sh
     ls "$@"