我怎样才能在中间写一个带有参数的PowerShell别名

我怎样才能在中间写一个带有参数的PowerShell别名

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

问题描述

我试图设置一个Windows PowerShell别名来运行具有特定参数的MinGW的g ++可执行文件。但是,这些参数需要在文件名和其他参数之后。我不想经历试图建立一个功能和所有这一切的麻烦。有没有一种方法可以简单地说出如下内容:

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

或者这些行中的内容?我并不熟悉PowerShell,并且我很难找到解决方案。任何人?

解决方案

您希望使用一个函数,而不是别名,正如Roman提到的。就像这样:

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

$ b

试试这个,下面是一个简单的例子:

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

您可能还想将其放入配置文件中,以便在运行PowerShell时使其可用。您的个人资料文件的名称包含在 $ profile 中。


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 ..."

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

解决方案

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>

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别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:10