传递感叹号,方括号作为Powershell中可执行参数的一部分

时间:2019-03-06 13:25:10

标签: powershell syntax command-line-arguments

在git中,如果我们想从diff输出中排除文件(在bash上),我们将执行以下操作:

git diff -- !(file.txt)

但这在powershell中是不允许的。因此,有没有办法在Powershell提示中实现这一目标?

1 个答案:

答案 0 :(得分:1)

只需单引号您的论点:

def __init__(self, *args, **kwargs):
      super(ProductForm, self).__init__(*args, **kwargs)
      self.helper = FormHelper()
      self.helper.form_class = 'form-horizontal'
      self.helper.label_class = 'col-sm-4'
      self.helper.field_class = 'col-sm-8'
      self.helper.form_id = 'product-modelform'
      self.helper.form_tag = False
      self.helper.layout = Layout(
      Div(
        Div('car_model_make','status_is_secondhand', css_class='col-lg-6 col-md-6 col-sm-12'),
        Div('seller','buyer', css_class='col-lg-6 col-md-6 col-sm-12'),
        css_class='row'
        )
      )

单引号使PowerShell可以按字面意义对待字符串,并防止其解释字符。例如git diff -- '!(file.txt)' 作为其自身的元字符。

在调用目标程序之前,PowerShell在必要时根据需要重新引用参数。即:

  • 如果包含空格以及某些不常见的情况(请参阅下面的链接),它将在(中包含一个参数。

  • 它会传递而不用引号。

注意:这种无形的重新引用存在一些陷阱-请参见Layouts