deostroll
deostroll

Reputation: 11975

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 -- !(file.txt)

But this is disallowed in powershell. Hence is there a way to achieve this in the powershell prompt?

Upvotes: 1

Views: 283

Answers (1)

mklement0
mklement0

Reputation: 437618

Simply single-quote your argument:

git diff -- '!(file.txt)'

Single-quoting makes PowerShell treat the string literally and prevents it from interpreting chars. such as ( as its own metacharacters.

Before invoking the target program, PowerShell re-quotes arguments if and as needed, behind the scenes; 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.

Upvotes: 1

Related Questions