-
Notifications
8000
You must be signed in to change notification settings - Fork 7.6k
globbing for native commands is too agressive #3931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Just to state it explicitly: globs shouldn't be expanded inside
Only unquoted tokens should ever be subject to globbing, as in POSIX-like shells. |
Just noticed this after moving to Beta on OSX. Maybe a recent regression? It makes using
|
Yes, not really a regression, it a new feature in beta-1 |
Is there a way to disable globbing entirely and opt back in to the Windows-style behavior? Even when it works by design, I kind of hate it. e.g. |
For this specific case |
Bump. Any update? This is preventing me from moving to beta on non-Windows. |
Polite ping @BrucePay |
Another example of native utility that became unusable is
|
And yet another example of globbbing messing up invocation of a native executable:
BTW the suggested workaround of escaping the |
So I was trying out my home grown echoargs in my WSL/Bash shell and noticed that given this command (in Bash): hillr@HILLR1:~$ echoargs g* --package_filter FOO/* You get this output:
RE globbing, how does Bash know to glob the first argument |
Bash (per POSIX):
My assumption has been that the idea behind PowerShell's native globbing is to emulate POSIX-shell rules (is that not true?), so in your earlier conan info --only "None" --package_filter 'PkgName/*' --cwd ../.. |
Quoting doesn't work in PowerShell (does work from Bash). That is part or the problem with PowerShell's aggressive globbing:
That BTW you're right about Bash not finding anything that matched |
Sorry for the reposts - I didn't want to clutter this thread with piecemeal insights. Indeed: that it currently doesn't work as I described and instead unexpectedly works as you demonstrate is the reason this issue was created. What you're seeing is a variation of what @vors experienced, and demonstrates both current problems (deviations from POSIX-shell behavior as of beta 8):
|
Thanks for sharing the POSIX design. I readily acknowledge that there is a lot of value in offering this well-established behavior to PowerShell users, even as a default on unix systems. This makes PowerShell easier to pick up for folks coming from that ecosystem. By no means am I opposed to PowerShell having this capability. But dang, that's totally idiotic. I really really hope there can be an option to disable this and use Windows-style (e.g. no) globbing, even on Unix. I have to switch back and forth between Windows and Mac pretty frequently, and it's been fantastic being able to use PowerShell on both. But the introduction of globbing on Mac was a complete show-stopper. I've had to stick with the alpha builds due to this. Even if the overly-aggressive stuff is fixed and behavior matches POSIX as described above, it still sounds terrible to me. |
Same here for us on Ubuntu.
Agreed. You can disable pathname expansion globbing in Bash with |
BTW a question for the Bash savvy. We expect that some folks will continue to live in Bash but we want them to be able to use PowerShell scripts in our repo. So we've shebang'd them and committed them with chmod=+x. The problem comes when they want use Bash globbing with a PowerShell command. Bash globbing space separates the files and that messes up our PowerShell command. Internally, it can do the wildcard resolution but it is kind of sucky to have to tell Bash users they have to put wildcards in quotes when calling PowerShell scripts. Is there an option in Bash, to get it to generate glob lists that are comma separated? |
No: the globbing is only applied when calling external utilities, on Unix, so nothing changes for calls to cmdlets / functions / *.ps1 PS scripts - or at all on Windows. Note: Globbing is applied when passing arguments to an executable PowerShell script with a shebang line, as it technically is an external utility too. |
I don't think there is such an option - arguments are strictly space-separated in the Unix world, and there is no concept of an array-valued argument in the shell. You could use a As an aside: even a comma-separated list wouldn't help you, because PowerShell doesn't recognize arrays in arguments passed to it from the outside; e.g., |
So Bash users need to know to quote wildcard arguments. Guess that's just the way it'll have to be.
Well that appears to be a new bug. Has that been filed yet? So how do I direct my script users to pass array args to my PowerShell script from Bash? Sigh.. 8000 . |
I agree that passing arrays from the outside would be nice, but has that really ever worked? I discovered the issue a while ago and assumed it was a by-design limitation of the CLI's argument parsing, similar to how all arguments are interpreted as literal strings. |
Well, it is something that Remove-Item foo.txt, bar.txt, baz.txt The question is what do Bash users expect? Presumably us PowerShell users will be using PowerShell. However, we will tell our Bash buddies how to run our PowerShell scripts and we're going to have to know that the array literal syntax we're used to in PowerShell isn't going to work in Bash. |
They expect to pass a list (array) - whose semantics are known to the target utility only - as either a single whitespace-less argument - e.g., to pass column names To Bash it is just a single argument in either case. So, at least with how the PowerShell CLI currently works, the answer is again:
From within PowerShell, if you call an external utility - including a shebang-line PS script - with an array argument:
|
Oh, at last I found this issue. There is a real-life example when globbing interfere when it shouldn't - SELinux file context management through semanage (of course I leared this hard way, in the middle of writing deployment script).
|
I think at this point there is agreement that "Unix-native" globbing in PowerShell is broken, but we don't know yet how it will be fixed. It's been laid out here how POSIX-like shells handle globbing, which decide whether to apply globbing based on the distinction between quoted and unquoted tokens - and anyone with Unix shell-scripting experience is aware of that. Both concepts are alien to PowerShell, where
Two worlds collide here, and something's gotta give. Adopting the quoted-vs.-unquoted distinction at least for literal unquoted tokens for calls to external utilities seems like a reasonable compromise to me, As an aside re
A decision was made not to adapt |
@mklement0 Could you please review ##5188 ? |
@iSazonov Oops! Sorry I missed that a fix is already underway - will take a look. |
Also fix some minor issues with exceptions being raised when resolving the path - falling back to no glob. Fix: PowerShell#3931 PowerShell#4971
Steps to reproduce
Intuitively globbing should not kick-in inside the single-quoted strings.
Expected behavior
Works, output is
11:1
, like in bash.Actual behavior
The error is pretty confusing for a unix user.
Workaround
Escape
*
by a backtick in the regex.Environment data
The text was updated successfully, but these errors were encountered: