别名在PowerShell中从在Unix的别名不同炮弹。您只能将cmdlet,函数或程序的名称别名,而不能包含参数。从Get-Help Set-Alias
报价:
NAME
Set-Alias
SYNOPSIS
Creates or changes an alias (alternate name) for a cmdlet or other command
element in the current Windows PowerShell session.
SYNTAX
Set-Alias [-Name] [-Value] [-Description ] [-Force]
[-Option ] [-PassThru] [-Scope ] [-Confirm]
[-WhatIf] []
DESCRIPTION
The Set-Alias cmdlet creates or changes an alias (alternate name) for a cmdlet or for a command element, such as a function, a script, a file, or other executable. You can also use Set-Alias to reassign a current alias
to a new command, or to change any of the properties of an alias, such as
its description. Unless you add the alias to the Windows PowerShell profile,
the changes to an alias are lost when you exit the session or close Windows
PowerShell.
你可以做什么用的参数的默认设置运行外部程序是定义默认设置为一个数组,像这样运行程序:
$CARGS = '-std=C99', '-pedantic', '-Wall'
gcc $CARGS -more arguments here ...
由于@ChrisN在下面的评论中建议,如果您想要在所有PowerShell实例中预先定义变量$CARGS
,则可以将其添加到custom PowerShell profile(例如,%UserProfile%\Documents\WindowsPowerShell\profile.ps1
为您的用户)。
您无法创建运行带参数的命令的别名,您需要创建一个函数。请参阅http://stackoverflow.com/questions/4166370/how-can-i-write-a-powershell-alias-with-arguments-in-the-middle – nos 2014-10-06 17:17:22
可能的重复[如何使用参数编写PowerShell别名在中间?](https://stackoverflow.com/questions/4166370/how-can-i-write-a-powershell-alias-with-arguments-in-the-middle) – 2017-09-22 19:21:25