how do i search for an empty string in PowerShell? #1713
-
What version of ripgrep are you using?
How did you install ripgrep?
What operating system are you using ripgrep on?
Describe your bug.I cannot perform an empty search using Powershel Core 7. This causes programs like What are the steps to reproduce the behavior?The following code produces rg '' The use of What is the expected behavior?I expect RipGrep to match all lines in all files like it does with bash. In fact, you can try these two commands and you will see pwsh fail and bash succeed. pwsh -c "rg ''" bash -c "rg ''" |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Try |
Beta Was this translation helpful? Give feedback.
-
I forgot to specified I tried that and |
Beta Was this translation helpful? Give feedback.
-
I'm not sure then. My guess is that this is a PowerShell issue and not a ripgrep issue, but it will be a while before I'm able to spin up a Windows machine and test this for myself. Others are encouraged to weigh in here! |
Beta Was this translation helpful? Give feedback.
-
Indeed, this is purely a PowerShell issue: empty-string arguments are simply discarded, regrettably; argument-passing to external programs has always been fundamentally broken in PowerShell, notably also with respect to handling embedded Workarounds:
This workaround is future-proof, but the use of For now, the following works too, but it shouldn't, and if PowerShell/PowerShell#1995 ever gets fixed - there's talk of providing a fix via an experimental feature now - it will stop working: PS> rg '""' |
Beta Was this translation helpful? Give feedback.
Indeed, this is purely a PowerShell issue: empty-string arguments are simply discarded, regrettably; argument-passing to external programs has always been fundamentally broken in PowerShell, notably also with respect to handling embedded
"
chars.; backward-compatibility concerns have prevented a fix so far - see PowerShell/PowerShell#1995Workarounds:
This workaround is future-proof, but the use of
--%
has important side effects: see--%
, the stop-parsing symbol.For now, the following works too, but it shouldn't, and if PowerShell/PowerShell#1995 ever gets fixed - there's talk of providing a fix via an experimental feature now - it will stop working: