如何编写带有中间参数的 PowerShell 别名? [英] How can I write a PowerShell alias with arguments in the middle?

查看:26
本文介绍了如何编写带有中间参数的 PowerShell 别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 Windows PowerShell 别名以使用某些参数运行 MinGW 的 g++ 可执行文件.但是,这些参数需要跟在文件名和其他参数之后.我不想经历尝试设置功能和所有这些的麻烦.有没有办法简单地说:

I'm trying to set up a Windows PowerShell alias to run MinGW's g++ executable with certain parameters. However, these parameters need to come after the file name and other arguments. I don't want to go through the hassle of trying to set up a function and all of that. Is there a way to simply say something like:

alias mybuild="g++ {args} -lib1 -lib2 ..."

或类似的东西?我对 PowerShell 并不十分熟悉,而且我很难找到解决方案.有人吗?

or something along those lines? I am not all that familiar with PowerShell, and I'm having a difficult time finding a solution. Anyone?

推荐答案

您想使用函数,而不是像 Roman 提到的别名.像这样:

You want to use a function, not an alias, as Roman mentioned. Something like this:

function mybuild { g++ $args -lib1 -lib2 ... }

要试试这个,这里有一个简单的例子:

To try this out, here's a simple example:

PS> function docmd { cmd /c $args there }
PS> docmd echo hello
hello there
PS> 

您可能还想将它放在您的配置文件中,以便在您运行 PowerShell 时随时可用.您的配置文件的名称包含在 $profile 中.

You might also want to put this in your profile in order to have it available whenever you run PowerShell. The name of your profile file is contained in $profile.

这篇关于如何编写带有中间参数的 PowerShell 别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆