Say I am wanting to grep the raw string ["data-foo"]
Under git bash, the following returns the expected results
git grep --fixed-strings '["data-foo"]'
However, under powershell, I cannot get any results with any of these variants:
git grep --fixed-strings '["data-foo"]';
git grep --fixed-strings "[""data-foo""]";
$s = '["data-foo"]'; git grep --fixed-strings $s;
git grep --fixed-strings '\\["data-foo"\\]';
git grep --fixed-strings '\["data-foo"\]';
My understanding is that --fixed-strings should prevent git from attempting to parse the argument, and using single-quotes in powershell strings should prevent powershell string interpolation.
That leaves me to guess that somehow powershell is still parsing the string argument before actually handing it to the git binary, but I've been unable to determine why it would or how to properly "escape" the argument, since the raw string (e.g. $s) is properly echoed on the powershell console.
(Last tested with git version 2.39.2.windows.1)
\-escaping of embedded"characters is required in arguments passed to external programs. This has been fixed in PowerShell 7.3.0, with selective exceptions on Windows, for now by default - though a future version may revert to the old, broken behavior, requiring opt-in for the fix. See the linked duplicate for details. stackoverflow.com/a/59036879/45375git grep --fixed-strings '[\"data-foo\"]'in PowerShell up to v7.2.x. In v7.3+, you may have to set$PSNativeCommandArgumentPassing = 'Legacy'for this to work, or you can set$PSNativeCommandArgumentPassing = 'Standard'and usegit grep --fixed-strings '["data-foo"]'as-is.$PSVersionTableshows I'm running on powershell 5.1. I mistakenly thought the square brackets were the problem because when I removed the brackets I got results - but I didn't notice the"weren't actually part of the pattern results matched by git under powershell.