繁体   English   中英

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

[英]Create an alias to a command that has spaces in it

我的用例是创建一个用于打开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...

花括号

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.

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

function xfirefox {
    Start-Process firefox.exe $args
}

然后你可以像这样启动:

xfirefox
xfirefox http://www.stackoverflow.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM