Skip to content

Native globbing on Unix platforms should pass syntactically-invalid-as-globbing-patterns unquoted literals through as-is #4971

Closed

Description

Related: #3931

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)

Activity

  1. 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
  2. SteveL-MSFT commented on Oct 1, 2017

    @SteveL-MSFT
    Member

    It seems the downside to making this change is if the user intended to use a valid pattern but typed it wrong

  3. mklement0 commented on Oct 2, 2017

    @mklement0
    ContributorAuthor

    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:

    $ 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]
      []
    

    shall is a Unix utility of mine that runs a shell command against multiple POSIX-like shells.

  4. mklement0 commented on Oct 2, 2017

    @mklement0
    ContributorAuthor

    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.

  5. lzybkr commented on Nov 1, 2017

    @lzybkr
    Contributor

    Closed via #5188.

  6. iSazonov commented on Nov 12, 2017

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Can we remove Review-Committee review and add Fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions