gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:06:44 25 4
gpt4 key购买 nike

我的用例是为打开 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

关于powershell - 为包含空格的命令创建别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26290052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com