Unix: Native globbing cannot be bypassed when using splatting #24178
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Note: This has been reported before, but not as a dedicated issue:
- By @jborean93 in Different behavior on Linux vs. Windows for passing "*" to az cli #24170 (comment)
- Prior to that, by @andrewhickman in Add an option to disable globbing on Linux #17176 (comment)
On Unix, barewords passed as arguments to external (native) programs are subject to globbing (filename expansion), if they contain *
or ?
, for compatibility with native Unix shells.
-
In direct invocation, the way to avoid this is to quote the bareword, e.g.
'*'
-
However - and this constitutes the bug - when splatting, the globbing cannot be prevented:
# On Unix-like platforms.
/bin/echo @( '*' )
Note that using embedded quoting (e.g., @('"*"')
) is not an option, because it becomes part of the argument.
Expected behavior
*
should print verbatim.
Note:
-
The above assumes that
'*'
should not be treated like a bareword in the context of splatting, which in turn implies that you fundamentally cannot specify barewords that way, and would have to use something like@((Get-Item * -Name))
to manually perform the desired globbing. -
This strikes me as an acceptable trade-off and much preferable to the alternative: defaulting to interpretation as barewords, with a yet-to-be-devised opt-out method.
Actual behavior
The names of the files and subdirectories in the current directory print, because native globbing was applied.
Error details
No response
Environment data
PowerShell 7.5.0-preview.3 on Unix-like platforms.
Visuals
No response