为包含空格的命令创建别名

Sha*_*tin 9 powershell alias

我的用例是创建一个用于打开Firefox的别名.通常我用过Start-Process firefox.exe,这很好.不过,我想改为输入xfirefox.这是我尝试过的:

行情

Shaun> set-alias xfirefox "Start-Process firefox.exe"
Shaun> xfirefox
xfirefox : The term 'Start-Process firefox.exe' is not 
recognized as the name of a cmdlet, function, script file, 
or operable program...
Run Code Online (Sandbox Code Playgroud)

花括号

Shaun> set-alias xfirefox { Start-Process firefox.exe }
Set-Alias : Cannot evaluate parameter 'Value' because its 
argument is specified as a script block and there is no
input. A script block cannot be evaluated without input.
Run Code Online (Sandbox Code Playgroud)

Kei*_*ill 18

别名就是 - 命令名的别名 - 不是命令名加参数.你想要的是一个功能,例如:

function xfirefox {
    Start-Process firefox.exe $args
}
Run Code Online (Sandbox Code Playgroud)

然后你可以像这样启动:

xfirefox
xfirefox http://www.stackoverflow.com
Run Code Online (Sandbox Code Playgroud)