[英]passing exclamation, brackets as part of executable arguments in powershell
In git, if we want to exclude a file from diff output (on bash) we do something like follows:在 git 中,如果我们想从 diff 输出(在 bash 上)中排除一个文件,我们会执行如下操作:
git diff -- !(file.txt)
But this is disallowed in powershell.但这在powershell中是不允许的。 Hence is there a way to achieve this in the powershell prompt?
因此,有没有办法在 powershell 提示中实现这一点?
Simply single-quote your argument:简单地单引号你的论点:
git diff -- '!(file.txt)'
Single-quoting makes PowerShell treat the string literally and prevents it from interpreting chars.单引号使 PowerShell 按字面意思处理字符串并阻止它解释字符。 such as
(
as its own metacharacters.例如
(
作为它自己的元字符。
Before invoking the target program, PowerShell re-quotes arguments if and as needed , behind the scenes;在调用目标程序之前,PowerShell 在幕后根据需要重新引用参数; that is:
那是:
It encloses an argument in "..."
if it contains whitespace, and also in certain, less common scenarios (see link below).如果它包含空格,并且在某些不太常见的情况下(请参见下面的链接),它将在
"..."
包含一个参数。
It passes it without quotes otherwise.否则它不带引号通过它。
Note: There are pitfalls associated with this invisible re-quoting - see this answer .注意:这种不可见的重新引用存在一些陷阱 - 请参阅此答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.