question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Native globbing: Automatic globbing for native commands doesn't work with backtick-escaped spaces

See original GitHub issue

See also (the inverse problem): https://github.com/PowerShell/PowerShell/issues/18038

When calling external programs (native programs) on Unix-like platforms, wildcard patterns that you want automatic globbing applied to (as in Bash, for instance) must be unquoted, i.e. they must neither be enclosed in single quotes nor in double quotes.

Therefore, if you want globbing to be applied to a wildcard pattern that has spaces, for instance, you need to individually escape the space, namely as

However, the automatic globbing mechanism currently doesn’t recognize that and doesn’t expand such patterns.

Steps to reproduce

On Linux (native globbing is currently fundamentally broken on macOS, and isn’t applied on Windows)

Push-Location temp:/
touch 'a b.txt'

/bin/echo a` * | Should -Be 'a b.txt'

Remove-Item 'a b.txt'
Pop-Location

Expected behavior

The test should succeed.

Actual behavior

The test fails, because the pattern is not expanded ('a *' is echoed).

Environment data

PowerShell Core v7.0.0-preview.3 

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dkaszewscommented, Sep 6, 2022

Workaround is to wrap any globbing with (Get-ChildItem ...). This is also a problem on Windows using utilities ported from Unix which expect globbing to be expanded by shell. Examples:

vim *.txt # bash: opens all txt files bash, pwsh: opens file '*.txt'
vim (Get-ChildItem *.txt)  # bash and pwsh: opens all txt files
1reaction
mklement0commented, Oct 7, 2019

@iSazonov: Not in terms of native globbing, as far as I can tell, but you can do the following:

 /bin/echo (Get-Item 'a *').Name
Read more comments on GitHub >

github_iconTop Results From Across the Web

Native globbing: character-individual backtick escaping of ...
Native globbing : Automatic globbing for native commands doesn't work with backtick-escaped spaces #10683. Open.
Read more >
Glob pattern works in shell command but not in Perl backticks
I created the files and the Perl script outputs them for me. · Also note you're not using a regular expression, but a...
Read more >
bash - Filenames with spaces in backtick substitution
I tried ls `echo 'with space'` . The arguments passed to ls are 'with and space' . Trying to escape the space using...
Read more >
PowerShell and external commands done right
The backticks (the funny looking single-quotes) are there to escape the following character, similar to the \" in C-based languages, or double- ...
Read more >
glob — Unix style pathname pattern expansion
The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell, although results are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found