-
I have had a bunch of frustrating experiences searching for string literals in software with ripgrep in PowerShell on Windows, which I initially thought was a ripgrep issue, but it appears to instead be a severe difference between how my shell works and how I expect it to work. I wrote a C++ program that prints its argv verbatim. I include a few tests below:
I even thought I was being hit by some incredibly strange libc misfeature so I wrote a rust program which passes a parameter with quotes in it .... and got this:
Command::new("../test.exe")
.arg("a")
.arg("\"\"\"b")
.arg("\"c\"")
.spawn()
.unwrap(); I am at my wits' end. How can I search something with double quotes in it on Windows with PowerShell 5? It just seems to eat all double quotes going to external programs, unconditionally. Strangely enough, PowerShell 7 (the open source one) passes a quadruple quoted string (wHat) as single quoted to the callee program. All of the tests above are PowerShell 5. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I personally have no idea. I don't use PowerShell. Someone else will need to field this one. But indeed, ripgrep isn't doing anything funny with its arguments. Have you tried using @r-darwish maybe you know the answer to this? |
Beta Was this translation helpful? Give feedback.
-
Apparently, escaping the quotes with Powershell has some complex argument conversion magic because it tries to achieve a delicate balance between being a language with actual types but still be useful as a shell language without forcing you to quote every string or escape any hyphen between numbers so it won't be considered as the minus operator. I'm not sure what's CMD's excuse, though. What I don't understand is why the Edit: This answer is the best that I found. |
Beta Was this translation helpful? Give feedback.
Apparently, escaping the quotes with
\
seems to do the trick in both Powershell 5 and 7. Cmd seems to be the oddest one as it converts the double quotes into single quotesPowershell has some complex argument conversion magic because it tries to achieve a delicate balance between being a language with actual types but still be useful as a shell language without forcing you to quote every string or escape any hyphen between numbers so it won't be considered as the minus operator. I'm not sure what's CMD's excuse, though.
What I don't understand is why the
\
did the trick and not `, which is the actual escape character in powershell, but I'm sure someone in StackOverflow will be happy to p…