Skip to content

how do i search for an empty string in PowerShell? #1713

Answered by mklement0
eruizc-dev asked this question in Q&A
Discussion options

You must be logged in to vote

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#1995

Workarounds:

PS> rg --% ""

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:

PS> rg '""'

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@BurntSushi
Comment options

Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1713 on December 10, 2020 18:57.