alias
is
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
command
Command may refer to:
Computing
* Command (computing), a statement in a computer language
* command (Unix), a Unix command
* COMMAND.COM, the default operating system shell and command-line interpreter for DOS
* Command key, a modifier key on A ...
that defines a word that the shell replaces with associated text before interpreting a command line. It is often used to enhance productivity by abbreviating a command or for including commonly-used arguments with a command. The command is available in
Unix shell
A Unix shell is a Command-line_interface#Command-line_interpreter, command-line interpreter or shell (computing), shell that provides a command line user interface for Unix-like operating systems. The shell is both an interactive command languag ...
s,
AmigaDOS
AmigaDOS is the disk operating system of the AmigaOS, which includes file systems, file and directory manipulation, the command-line interface, and file Redirection (computing), redirection.
In AmigaOS 1.x, AmigaDOS is based on a TRIPOS port by ...
,
4DOS
4DOS is a command-line interpreter by JP Software, designed to replace the default command interpreter COMMAND.COM in MS-DOS and Windows. It was written by Rex C. Conn and Tom Rawson and first released in 1989. Compared to the default, it has ...
/
4NT,
FreeDOS
FreeDOS (formerly PD-DOS) is a free software operating system for IBM PC compatible computers. It intends to provide a complete MS-DOS-compatible environment for running Legacy system, legacy software and supporting embedded systems. FreeDOS ca ...
,
KolibriOS
KolibriOS is an open-source operating system for x86 computers, written completely in FASM assembly language. It has been developed since 2004, forked from MenuetOS, and supports i586 CPU, CPUs or newer. KolibriOS is small sized and fits on a sin ...
,
PowerShell
PowerShell is a shell program developed by Microsoft for task automation and configuration management. As is typical for a shell, it provides a command-line interpreter for interactive use and a script interpreter for automation via a langu ...
,
ReactOS
ReactOS is a Free and open-source software, free and open-source operating system for i586/amd64 personal computers that is intended to be binary-code compatibility, binary-compatible with computer programs and device drivers developed for Wind ...
,
EFI shell,
and
IBM i
IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS in 2 ...
. Aliasing functionality in
MS-DOS
MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few op ...
and
Command Prompt
A command-line interface (CLI) is a means of interacting with software via commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user-friendly alternativ ...
is provided by the
DOSKEY
DOSKEY is a command in DOS, OS/2, Windows, and ReactOS that adds command history, macro functionality, and improved editing features to the COMMAND.COM and cmd.exe command-line interpreter shells.
History
The command was included as a termi ...
command.
Since aliases are defined only for a shell session, regularly-used aliases are often defined in a session startup
shell script
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be command languages. Typical operations performed by shell scripts include file manipu ...
such as
.bashrc
. The commands may either be written in the config script directly or
source
Source may refer to:
Research
* Historical document
* Historical source
* Source (intelligence) or sub source, typically a confidential provider of non open-source intelligence
* Source (journalism), a person, publication, publishing institute ...
d from a separate file.
Aliases were introduced in the
C shell
The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the ...
to survive in descendant shells such as
tcsh
tcsh ( “tee-see-shell”, “tee-shell”, or as “tee see ess aitch”, tcsh) is a Unix shell based on and backward compatible with the C shell (csh).
Shell
It is essentially the C shell with programmable command-line completion, command- ...
and
bash. As these aliases were limited to one line they were useful for creating relatively simple shortcut commands, but not more complex constructs. Older versions of the
Bourne shell
The Bourne shell (sh) is a shell command-line interpreter for computer operating systems. It first appeared on Version 7 Unix, as its default shell. Unix-like systems continue to have /bin/sh—which will be the Bourne shell, or a symbolic lin ...
did not offer aliases, but did provide functions, which are more powerful than the csh alias. Eventually, the csh alias was implemented in the
bash and
ksh shells. With shells that support both functions and aliases but no parameterized inline shell scripts, the use of functions wherever possible is recommended. None-the-less, aliases are necessary where chained aliases are required.
Features
Define
The following is an example that defines
gc
to be a command the performs the action
git
Git () is a distributed version control system that tracks versions of files. It is often used to control source code by programmers who are developing software collaboratively.
Design goals of Git include speed, data integrity, and suppor ...
commit
.
alias gc='git commit'
In C shell and tcsh there is no equals sign:
alias gc "git commit"
To define an alias in PowerShell, the
new-alias
cmdlet is used:
new-alias ci copy-item
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 , 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.
set-alias ci cls
In 4DOS/4NT shell, the
eset
command provides an interactive command line to edit an existing alias. For example:
eset /a cp
List
To view defined aliases:
alias
To list aliases in a way that allows for re-creating them by sourcing the output (not available in 4DOS/4NT or PowerShell):
alias -p
To report the definition of a particular alias name:
alias myAlias
Remove
In Unix shells and 4DOS/4NT, aliases can be removed via
unalias
. To remove the alias:
unalias copy
To remove all aliases (not available in 4DOS/4NT):
unalias -a
To remove all aliases in 4DOS/4NT:
unalias *
In PowerShell, an alias is removed from the drive via
remove-item
:
remove-item alias:ci
Ignore
In Unix shells, an aliased word can be used without replacement by using quotes. For example, consider the following command that defines an alias that invokes the original with options . To invoke the original command (without the options), the following syntax is used: or .
alias ls='ls -la'
In 4DOS/4NT shell, an asterisk is used. For example, the following defines to invoke the original (requires asterisk in the definition) with options . To later invoke the original , the syntax is .
alias dir = *dir /2/p
Chaining
Typically, aliases are used to replace the first word of a command line, but some shells such as and also support chaining replacing subsequent words.
For example, the following defines to invoke and to as a set of options. The command alias must end with a space to enable chaining.
alias list='ls '
alias long='-Flas'
Then, command line expands to .
The behavior provided by chaining is not possible via shell functions.
Command arguments
In the
C Shell
The C shell (csh or the improved version, tcsh) is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the ...
,
arguments
An argument is a series of sentences, statements, or propositions some of which are called premises and one is the conclusion. The purpose of an argument is to give reasons for one's conclusion via justification, explanation, and/or persua ...
can be embedded inside the command using the string . For example, with this alias:
alias ls-more 'ls \!* , more'
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 ,
alias ls-more 'ls , more'
would instead expand to
ls , more /etc /usr
which incorrectly attempts to open the directories in ''more''.
Some shells such as bash and ksh do not support this syntax, but do provide for similar functionality via shell functions — see
§ Alternatives below.
Alternatives
Best practice is to only define an alias for a relatively simple command. Alternatives for more complicated logic include:
*
Shell script
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be command languages. Typical operations performed by shell scripts include file manipu ...
, provides a rich ability to implement a command
*
Symbolic link
In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory (called the "target") by specifying a path thereto.
Symbolic links are supported by POSIX and by most Unix-like operating syste ...
in the user's
PATH
A path is a route for physical travel – see Trail.
Path or PATH may also refer to:
Physical paths of different types
* Bicycle path
* Bridle path, used by people on horseback
* Course (navigation), the intended path of a vehicle
* Desir ...
(such as
/bin
); in some cases may allow access to a buried command function for the small number of commands that use their invocation name to select the mode of operation
* Shell function, especially if the command being created needs to modify the internal
runtime environment
In computer programming, a runtime system or runtime environment is a sub-system that exists in the computer where a program is created, as well as in the computers where the program is intended to be run. The name comes from the compile time ...
of the shell (such as
environment variables
An environment variable is a user-definable Value (computer science), value that can affect the way running process (computing), processes will behave on a computer. Environment variables are part of the environment in which a process runs. Fo ...
), needs to change the shell's
working directory
In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with the process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just c ...
, or must be implemented in a way which guarantees that it appear in the command search path for anything but an interactive shell (especially any "safer" version of , , and so forth)
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 . To prevent a function from
calling itself, use
command
Command may refer to:
Computing
* Command (computing), a statement in a computer language
* command (Unix), a Unix command
* COMMAND.COM, the default operating system shell and command-line interpreter for DOS
* Command key, a modifier key on A ...
:
ls ()
. In older Bourne shells, use
/bin/ls
instead of
command ls
.
References
Further reading
*
External links
*
Bash man page for aliasby The Linux Information Project (LINFO)
{{Unix commands
Alias
IBM i Qshell commands
ReactOS commands
Windows commands
Unix SUS2008 utilities
Windows administration