fbpx
Wikipedia

alias (command)

In computing, alias is a command in various command-line interpreters (shells), which enables a replacement of a word by another string.[1] It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command. alias is available in Unix shells, AmigaDOS, 4DOS/4NT, FreeDOS, KolibriOS, Windows PowerShell, ReactOS, and the EFI shell.[2] Aliasing functionality in the MS-DOS and Microsoft Windows operating systems is provided by the DOSKey command-line utility.

An alias will last for the life of the shell session. Regularly used aliases can be set from the shell's rc file (such as .bashrc) so that they will be available upon the start of the corresponding shell session. The alias commands may either be written in the config file directly or sourced from a separate file.

History edit

In Unix, aliases were introduced in the C shell and survive in descendant shells such as tcsh and bash. C shell aliases were strictly limited to one line. This was useful for creating simple shortcut commands, but not more complex constructs. Older versions of the Bourne shell did not offer aliases, but it did provide functions, which are more powerful than the csh alias concept. The alias concept from csh was imported into Bourne Again Shell (bash) and the Korn shell (ksh). With shells that support both functions and aliases but no parameterized inline shell scripts, the use of functions wherever possible is recommended. Cases where aliases are necessary include situations where chained aliases are required (bash and ksh). The alias command has also been ported to the IBM i operating system.[3]

Usage edit

Creating aliases edit

Common Unix shells edit

Non-persistent aliases can be created by supplying name/value pairs as arguments for the alias command. In Unix shells the syntax is:

alias gc='git commit' 

C shell edit

The corresponding syntax in the C shell or tcsh shell is:

alias gc "git commit" 

This alias means that when the command gc is read in the shell, it will be replaced with git commit and that command will be executed instead.

4DOS edit

In the 4DOS/4NT shell the following syntax is used to define cp as an alias for the 4DOS copy command:

alias cp copy 

Windows PowerShell edit

To create a new alias in Windows PowerShell, the new-alias cmdlet can be used:

new-alias ci copy-item 

This creates a new alias called ci that will be replaced with the copy-item cmdlet when executed.

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.

Viewing currently defined aliases edit

To view defined aliases the following commands can be used:

alias # Used without arguments; displays a list of all current aliases alias -p # List aliases in a way that allows re-creation by sourcing the output; not available in 4DOS/4NT and PowerShell alias myAlias # Displays the command for a defined alias 

Overriding aliases edit

In Unix shells, it is possible to override an alias by quoting any character in the alias name when using the alias. For example, consider the following alias definition:

alias ls='ls -la' 

To override this alias and execute the ls command as it was originally defined, the following syntax can be used:

'ls' 

or

\ls 

In the 4DOS/4NT shell it is possible to override an alias by prefixing it with an asterisk. For example, consider the following alias definition:

alias dir = *dir /2/p 

The asterisk in the 2nd instance of dir causes the unaliased dir to be invoked, preventing recursive alias expansion. Also the user can get the unaliased behaviour of dir at the command line by using the same syntax:

*dir 

Changing aliases edit

In Windows PowerShell, the set verb can be used with the alias cmdlet to change an existing alias:

set-alias ci cls 

The alias ci will now point to the cls command.

In the 4DOS/4NT shell, the eset command provides an interactive command line to edit an existing alias:

eset /a cp 

The /a causes the alias cp to be edited, as opposed to an environment variable of the same name.

Removing aliases edit

In Unix shells and 4DOS/4NT, aliases can be removed by executing the unalias command:

unalias copy # Removes the copy alias unalias -a # The -a switch will remove all aliases; not available in 4DOS/4NT unalias * # 4DOS/4NT equivalent of `unalias -a` - wildcards are supported 

In Windows PowerShell, the alias can be removed from the alias:\ drive using remove-item:

remove-item alias:ci # Removes the ci alias 

Features edit

Chaining edit

An alias usually replaces just the first word. But some shells, such as bash and ksh, allow a sequence or words to be replaced. This particular feature is unavailable through the function mechanism.

The usual syntax is to define the first alias with a trailing space character. For instance, using the two aliases:

alias list='ls ' # note the trailing space to trigger chaining alias long='-Flas' # options to ls for a long listing 

allows:

list long myfile # becomes "ls -Flas myfile" when run 

for a long listing, where "long" is also evaluated as an alias.

Command arguments edit

In the C Shell, arguments 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.[4]

The Bash and Korn shells instead use shell functions — see § Alternatives below.

Alternatives edit

Aliases should usually be kept simple. Where it would not be simple, the recommendation is usually to use one of the following:

  • Shell scripts, which essentially provide the full ability to create new system commands.
  • Symbolic links in the user's PATH (such as /bin). This method is useful for providing an additional way of calling the command, and 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 functions, especially if the command being created needs to modify the internal runtime environment of the shell itself (such as environment variables), needs to change the shell's current working directory, or must be implemented in a way which guarantees they it appear in the command search path for anything but an interactive shell (especially any "safer" version of rm, cp, mv and so forth).

The most common form of aliases, which just add a few options to a command and then include the rest of the command line, can be converted easily to shell functions following this pattern:

alias ll='ls -Flas' # long listing, alias ll () { ls -Flas "$@" ; } # long listing, function 

To prevent a function from calling itself recursively, use command:

ls () { command ls --color=auto "$@" ; } 

In older Bourne shells use /bin/ls instead of command ls.

References edit

  1. ^ 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.
  2. ^ "EFI Shells and Scripting". Intel. Retrieved 2013-09-25.
  3. ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Retrieved 2020-09-05.
  4. ^ . UNIXhelp. University of Edinburgh. Archived from the original on 2012-11-25.

Further reading edit

External links edit

alias, command, aliasing, variables, programming, language, aliasing, computing, this, article, needs, additional, citations, verification, please, help, improve, this, article, adding, citations, reliable, sources, unsourced, material, challenged, removed, fi. For the aliasing of variables in a programming language see Aliasing computing This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Alias command news newspapers books scholar JSTOR July 2013 Learn how and when to remove this template message In computing alias is a command in various command line interpreters shells which enables a replacement of a word by another string 1 It is mainly used for abbreviating a system command or for adding default arguments to a regularly used command alias is available in Unix shells AmigaDOS 4DOS 4NT FreeDOS KolibriOS Windows PowerShell ReactOS and the EFI shell 2 Aliasing functionality in the MS DOS and Microsoft Windows operating systems is provided by the DOSKey command line utility aliasExample of alias commandOriginal author s Bill JoyDeveloper s Various open source and commercial developersOperating systemUnix Unix like AmigaDOS FreeDOS Microsoft Windows ReactOS AROS KolibriOS IBM iPlatformCross platformTypeCommandAn alias will last for the life of the shell session Regularly used aliases can be set from the shell s rc file such as bashrc so that they will be available upon the start of the corresponding shell session The alias commands may either be written in the config file directly or sourced from a separate file Contents 1 History 2 Usage 2 1 Creating aliases 2 1 1 Common Unix shells 2 1 2 C shell 2 1 3 4DOS 2 1 4 Windows PowerShell 2 2 Viewing currently defined aliases 2 3 Overriding aliases 2 4 Changing aliases 2 5 Removing aliases 3 Features 3 1 Chaining 3 2 Command arguments 4 Alternatives 5 References 6 Further reading 7 External linksHistory editIn Unix aliases were introduced in the C shell and survive in descendant shells such as tcsh and bash C shell aliases were strictly limited to one line This was useful for creating simple shortcut commands but not more complex constructs Older versions of the Bourne shell did not offer aliases but it did provide functions which are more powerful than the csh alias concept The alias concept from csh was imported into Bourne Again Shell bash and the Korn shell ksh With shells that support both functions and aliases but no parameterized inline shell scripts the use of functions wherever possible is recommended Cases where aliases are necessary include situations where chained aliases are required bash and ksh The alias command has also been ported to the IBM i operating system 3 Usage editCreating aliases edit Common Unix shells edit Non persistent aliases can be created by supplying name value pairs as arguments for the alias command In Unix shells the syntax is alias gc git commit C shell edit The corresponding syntax in the C shell or tcsh shell is alias gc git commit This alias means that when the command gc is read in the shell it will be replaced with a href Git html title Git git a commit and that command will be executed instead 4DOS edit In the 4DOS 4NT shell the following syntax is used to define cp as an alias for the 4DOS a href Copy command html title Copy command copy a command alias cp copy Windows PowerShell edit To create a new alias in Windows PowerShell the new alias cmdlet can be used new alias ci copy item This creates a new alias called ci that will be replaced with the copy item cmdlet when executed 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 Viewing currently defined aliases edit To view defined aliases the following commands can be used alias Used without arguments displays a list of all current aliases alias p List aliases in a way that allows re creation by sourcing the output not available in 4DOS 4NT and PowerShell alias myAlias Displays the command for a defined alias Overriding aliases edit In Unix shells it is possible to override an alias by quoting any character in the alias name when using the alias For example consider the following alias definition alias ls ls la To override this alias and execute the a href Ls html title Ls ls a command as it was originally defined the following syntax can be used ls or ls In the 4DOS 4NT shell it is possible to override an alias by prefixing it with an asterisk For example consider the following alias definition alias dir dir 2 p The asterisk in the 2nd instance of a href Dir command html title Dir command dir a causes the unaliased dir to be invoked preventing recursive alias expansion Also the user can get the unaliased behaviour of dir at the command line by using the same syntax dir Changing aliases edit In Windows PowerShell the set verb can be used with the alias cmdlet to change an existing alias set alias ci cls The alias ci will now point to the a href Cls command html class mw redirect title Cls command cls a command In the 4DOS 4NT shell the eset command provides an interactive command line to edit an existing alias eset a cp The a causes the alias cp to be edited as opposed to an environment variable of the same name Removing aliases edit In Unix shells and 4DOS 4NT aliases can be removed by executing the unalias command unalias copy Removes the copy alias unalias a The a switch will remove all aliases not available in 4DOS 4NT unalias 4DOS 4NT equivalent of unalias a wildcards are supported In Windows PowerShell the alias can be removed from the alias drive using remove item remove item alias ci Removes the ci aliasFeatures editChaining edit An alias usually replaces just the first word But some shells such as bash and ksh allow a sequence or words to be replaced This particular feature is unavailable through the function mechanism The usual syntax is to define the first alias with a trailing space character For instance using the two aliases alias list ls note the trailing space to trigger chaining alias long Flas options to ls for a long listing allows list long myfile becomes ls Flas myfile when run for a long listing where long is also evaluated as an alias Command arguments edit In the C Shell arguments 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 4 The Bash and Korn shells instead use shell functions see Alternatives below Alternatives editAliases should usually be kept simple Where it would not be simple the recommendation is usually to use one of the following Shell scripts which essentially provide the full ability to create new system commands Symbolic links in the user s a href PATH variable html title PATH variable PATH a such as a href bin html class mw redirect title bin bin a This method is useful for providing an additional way of calling the command and 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 functions especially if the command being created needs to modify the internal runtime environment of the shell itself such as environment variables needs to change the shell s current working directory or must be implemented in a way which guarantees they it appear in the command search path for anything but an interactive shell especially any safer version of rm cp mv and so forth The most common form of aliases which just add a few options to a command and then include the rest of the command line can be converted easily to shell functions following this pattern alias ll ls Flas long listing alias ll ls Flas long listing function To prevent a function from calling itself recursively use a href Command Unix html title Command Unix command a ls command ls color auto In older Bourne shells use bin ls instead of command ls References edit Rugheimer Hannes 2020 06 10 AmigaDOS quick reference Rugheimer Hannes Free Download Borrow and Streaming Internet Archive ISBN 9781557550491 Retrieved 2020 09 12 via Internet Archive EFI Shells and Scripting Intel Retrieved 2013 09 25 IBM IBM System i Version 7 2 Programming Qshell PDF IBM Retrieved 2020 09 05 Examples of passing arguments given to a command alias UNIXhelp University of Edinburgh Archived from the original on 2012 11 25 Further reading editMcElhearn Kirk 2006 The Mac OS X Command Line Unix Under the Hood John Wiley amp Sons ISBN 978 0470113851 External links edit nbsp The Wikibook Guide to Unix has a page on the topic of Commands alias define or display aliases Shell and Utilities Reference The Single UNIX Specification Version 4 from The Open Group Bash man page for alias The alias Command by The Linux Information Project LINFO Retrieved from https en wikipedia org w index php title Alias command amp oldid 1218860515 Removing aliases, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.