词条 | Alias (command) |
释义 |
| name = alias | logo = | screenshot = | screenshot size = | caption = | author = | developer = | released = | latest release version = | latest release date = | operating system = Unix and Unix-like, AmigaDOS, Microsoft Windows, ReactOS, AROS, KolibriOS | genre = Command | license = | website = }} In computing, alias is a command in various command-line interpreters (shells) such as Unix shells, AmigaDOS, 4DOS/4NT, KolibriOS[1] and Windows PowerShell, which enables a replacement of a word by another string.[2] It is mainly used for abbreviating a system command, or for adding default arguments to a regularly used command. The command is also available in the EFI shell.[3] Aliasing functionality in the MS-DOS and Microsoft Windows operating systems is provided by the DOSKey command-line utility. The ReactOS Command Prompt also includes the An alias will last for the life of the shell session. Regularly used aliases can be set from the shell's configuration file ( HistoryIn 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). UsageCreating aliasesUnixNon-persistent aliases can be created by supplying name/value pairs as arguments for the alias command. In Unix shells the syntax is: C shellThe corresponding syntax in the C shell or tcsh shell is: This alias means that when the command 4DOSIn the 4DOS/4NT shell the following syntax is used to define Windows PowerShellTo create a new alias in Windows PowerShell, the This creates a new alias called 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 aliasesTo view defined aliases the following commands can be used: Overriding aliasesIn Unix shells, if an alias exists for a command, it is possible to override the alias by surrounding the command with quotes or prefixing it with a backslash. For example, consider the following alias definition: To override this alias and execute the or 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: The asterisk in the 2nd instance of Changing aliasesIn Windows PowerShell, the The alias In the 4DOS/4NT shell, the The Removing aliasesIn Unix shells and 4DOS/4NT, aliases can be removed by executing the In Windows PowerShell, the alias can be removed from the alias:\\ drive using FeaturesChainingAn 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: allows: for a long listing, where "long" is also evaluated as an alias. Quoting quotesTo define an alias with single quotes, which itself needs to contain single quotes, you need to use several concatenated quoted strings. For example, to define an alias which would do: You cannot do However, you can surround Also, you can use single quotes quoted inside double quotes: .[4] You may also consider using a function instead of an alias. Command argumentsIn the C Shell, arguments can be embedded inside the command using the string {{mono|\\!*}}. For example, with this alias:
would instead expand to The Bash and Korn shells instead use shell functions — see Alternatives below. Typical aliasesSome commonly used, but deprecated, aliases in the Bash shell: Standard aliases of Windows PowerShell include: AlternativesAliases should usually be kept simple. Where it would not be simple, the recommendation is usually to use one of the following:
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: To make ls itself a function (note that "command ls" is Bash-specific, and that older Bourne shells would have used "/bin/ls" instead): References1. ^http://wiki.kolibrios.org/wiki/Shell 2. ^https://archive.org/details/1988-rugheimer-spanik-amigados-quick-reference 3. ^{{cite web | url = http://software.intel.com/en-us/articles/efi-shells-and-scripting/ | title = EFI Shells and Scripting | publisher = Intel | accessdate = 2013-09-25}} 4. ^[https://stackoverflow.com/questions/1250079/bash-escaping-single-quotes-inside-of-single-quoted-strings#1250279 Escaping single-quotes within single-quoted strings] 5. ^Examples of passing arguments given to a command alias {{webarchive|url=https://web.archive.org/web/20121125074502/http://unixhelp.ed.ac.uk/shell/alias_csh2.1.html |date=2012-11-25 }} External links
4 : Standard Unix programs|Windows commands|Unix SUS2008 utilities|Windows administration |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。