You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native globbing on Unix platforms should pass syntactically-invalid-as-globbing-patterns unquoted literals through as-is #4971
An unquoted token that is not a syntactically valid globbing pattern (wildcard expression) should be considered a literal to be passed as-is - not an error.
Note that, by default, bash retains whatever unquoted token you specify as-is, if it (a) happens not to be a valid globbing pattern or (b) happens not to match any files.
(Setting shopt -s nullglob, however, would result in syntactically valid non-matching globs evaluating to the empty string).
Steps to reproduce (Unix platforms)
/bin/echo []
Expected behavior
[]
Actual behavior
The specified wildcard character pattern is not valid: []
...
Environment data
PowerShell Core v6.0.0-beta.7 on macOS 10.12.6
PowerShell Core v6.0.0-beta.7 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.7 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
changed the title [-]Native globbing on Unix platforms should pass syntactically-invalid-as-globbing-patterns unquoted literals through as-is, as literals[/-][+]Native globbing on Unix platforms should pass syntactically-invalid-as-globbing-patterns unquoted literals through as-is[/+]on Oct 1, 2017
Implementing implicit globbing for external utilities on Unix platforms is an attempt to emulate the typical native shell behavior there.
Defining typical is tricky, as it depends on whether it refers to the default shell for interactive use - which is often bash - vs. running scripts with the POSIX-features-only /bin/sh shell (which is bash in its POSIX-compatible mode on some platforms (e.g., macOS), and dash on others (e.g, Ubuntu), and possibly a different implementation on others).
Either way, the following - run on macOS 10.12.6 - shows that both bash and dash (which is the closest thing to a POSIX-features-only shell I'm aware of) interpret unquoted [] as a literal by default:
In other words: while you could argue that it'd better for the shell to notify you of a malformed globbing pattern / expand a valid pattern that happens to match nothing to the empty string, this is not how things work on Unix platforms by default - and emulating the de-facto behavior on Unix platforms is the goal, I presume.
Activity
[-]Native globbing on Unix platforms should pass syntactically-invalid-as-globbing-patterns unquoted literals through as-is, as literals[/-][+]Native globbing on Unix platforms should pass syntactically-invalid-as-globbing-patterns unquoted literals through as-is[/+]SteveL-MSFT commentedon Oct 1, 2017
It seems the downside to making this change is if the user intended to use a valid pattern but typed it wrong
mklement0 commentedon Oct 2, 2017
Implementing implicit globbing for external utilities on Unix platforms is an attempt to emulate the typical native shell behavior there.
Defining typical is tricky, as it depends on whether it refers to the default shell for interactive use - which is often
bash- vs. running scripts with the POSIX-features-only/bin/shshell (which isbashin its POSIX-compatible mode on some platforms (e.g., macOS), anddashon others (e.g, Ubuntu), and possibly a different implementation on others).Either way, the following - run on macOS 10.12.6 - shows that both
bashanddash(which is the closest thing to a POSIX-features-only shell I'm aware of) interpret unquoted[]as a literal by default:$ shall -c '/bin/echo []' ✓ sh (bash variant) [0.01s] [] ✓ dash [0.00s] [] ✓ bash [0.00s] [] ✗ zsh [0.02s] zsh:1: no matches found: [] ✓ ksh [0.02s] []shallis a Unix utility of mine that runs a shell command against multiple POSIX-like shells.mklement0 commentedon Oct 2, 2017
In other words: while you could argue that it'd better for the shell to notify you of a malformed globbing pattern / expand a valid pattern that happens to match nothing to the empty string, this is not how things work on Unix platforms by default - and emulating the de-facto behavior on Unix platforms is the goal, I presume.
Glob native command args only when not quoted
lzybkr commentedon Nov 1, 2017
Closed via #5188.
iSazonov commentedon Nov 12, 2017
Steve Lee (@SteveL-MSFT) Can we remove Review-Committee review and add Fixed?
Glob native command args only when not quoted