我想知道如何在PowerShell中为开发Firefox扩展中使用的cmd执行set-alias:
cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp
我已将以下内容添加到Microsoft.PowerShell_profile.ps1中:
Set-Alias cfxp cfx run -p "C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
但是,当PowerShell启动时,它会显示错误:
Set-Alias : A positional parameter cannot be found that accepts argument 'run'.
At D:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:2 char:1
+ Set-Alias cfxp cfx run -p "C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Alias], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand
也尝试过:
Set-Alias cfxp "cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
另一个错误:
cfxp : The term 'cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp' is not recognized
as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ cfxp
+ ~~~~
+ CategoryInfo : ObjectNotFound: (cfx run -p C:\U...s\ripltbxm.cfxp:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
答案 0 :(得分:2)
在PowerShell中,只能为命令或cmdlet定义别名,而不能为包含参数的整个命令行定义别名:
NAME
New-Alias
SYNOPSIS
Creates a new alias.
[...]
DESCRIPTION
The New-Alias cmdlet creates a new alias in the current Windows
PowerShell session. Aliases created by using New-Alias are not
saved after you exit the session or close Windows PowerShell. You
can use the Export-Alias cmdlet to save your alias information to
a file. You can later use Import-Alias to retrieve that saved
alias information.
PARAMETERS
[...]
-Value <String>
Specifies the name of the cmdlet or command element that is
being aliased.
如果您想要使用参数运行特定命令的简写,则需要自定义函数。
function cfxp {
& cfx run -p "$env:APPDATA\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
}