The following is an example that defines gc to be a command the performs the action git commit.
In C shell and tcsh there is no equals sign:
To define an alias in PowerShell, the new-alias cmdlet is used:
In PowerShell, an alias cannot be used to specify default arguments for a command. Instead, this must be done by adding items to the collection $PSDefaultParameterValues, one of the PowerShell preference variables.
In PowerShell, the set verb is used to change an existing alias. The following changes the alias ci to invoke the cls command.
In 4DOS/4NT shell, the eset command provides an interactive command line to edit an existing alias. For example:
To view defined aliases:
To list aliases in a way that allows for re-creating them by sourcing the output (not available in 4DOS/4NT or PowerShell):
To report the definition of a particular alias name:
In Unix shells and 4DOS/4NT, aliases can be removed via unalias. To remove the copy alias:
To remove all aliases (not available in 4DOS/4NT):
To remove all aliases in 4DOS/4NT:
In PowerShell, an alias is removed from the alias:\ drive via remove-item:
In Unix shells, an aliased word can be used without replacement by using quotes. For example, consider the following command that defines an alias ls that invokes the original ls with options -la. To invoke the original ls command (without the options), the following syntax is used: 'ls' or \ls.
In 4DOS/4NT shell, an asterisk is used. For example, the following defines dir to invoke the original dir (requires asterisk in the definition) with options /2/p. To later invoke the original dir, the syntax is *dir.
Typically, aliases are used to replace the first word of a command line, but some shells such as bash and ksh also support chaining – replacing subsequent words.
For example, the following defines list to invoke ls and long to as a set of ls options. The command alias must end with a space to enable chaining.
Then, command line list long myfile expands to ls -Flas myfile.
The behavior provided by chaining is not possible via shell functions.
In the C Shell, arguments can be embedded inside the command using the string \!*. For example, with this alias:
ls-more /etc /usr expands to ls /etc /usr | more to list the contents of the directories /etc and /usr, pausing after every screenful. Without \!*,
would instead expand to ls | more /etc /usr which incorrectly attempts to open the directories in more.4
Some shells such as bash and ksh do not support this syntax, but do provide for similar functionality via shell functions — see § Alternatives below.
Best practice is to only define an alias for a relatively simple command. Alternatives for more complicated logic include:
A relatively simple alias that includes a few arguments and supports subsequent arguments, can be converted to a shell function in a relatively straightforward process. For example, alias alias ll='ls -Flas' can be implemented as function ll () { ls -Flas "$@" ;}. To prevent a function from calling itself, use command: ls () { command ls --color=auto "$@" ; }. In older Bourne shells, use /bin/ls instead of command ls.
Rugheimer, Hannes (2020-06-10). AmigaDOS quick reference : Rügheimer, Hannes : Free Download, Borrow, and Streaming : Internet Archive. ISBN 9781557550491. Retrieved 2020-09-12 – via Internet Archive. 9781557550491 ↩
"EFI Shells and Scripting". Intel. Retrieved 2013-09-25. http://software.intel.com/en-us/articles/efi-shells-and-scripting/ ↩
IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Retrieved 2020-09-05. /wiki/IBM ↩
"Examples of passing arguments given to a command alias". UNIXhelp. University of Edinburgh. Archived from the original on 2012-11-25. https://web.archive.org/web/20121125074502/http://unixhelp.ed.ac.uk/shell/alias_csh2.1.html ↩