-
Notifications
You must be signed in to change notification settings - Fork 7.2k
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
Consider introducing $IsUnix as an abstraction over $IsMacOS and $IsLinux #6518
Comments
Can we not have some kind of a separate space for variables like this, similar to the $env: variables on Windows? Like have an $Env:OperatingSystem automatic variable? |
@vexx32 before we declared PSCore6 GA (aka General Availability, aka done), the @PowerShell/powershell-committee discussed having a prefix/namespace such as $ps:IsWindows or $interop:IsWindows, however, it was deemed too big a breaking change for people already dependent on the existing variables (let alone the code churn we'd endure for our own code in this repo dependent on it). Since it's already shipped we won't be changing them so they are here to stay. We can still introduce an I would agree there is utility in having $IsUnix |
Struggling to see the utility of this. We already have $IsWindows so |
I'm opposed to this for several reasons. The first of which @RichardSiddaway has already covered regarding The second issue I take is with using First, the usage is contentious to the point of being inflammatory in some circles. While it is true, there is some shared heritage, it is also very true that Linus is not Unix. Second, in my years where I worked very heavily with various *nix distributions, BSD clones, and Solaris, The term My final issue is that, outside of distinguishing these systems from Windows, I don't see any utility in uniting them under a common banner. Not-Windows is what you want. The ecosystems between macOS and Linux are distinct enough to make Knowing something is Not-Windows is helpful so you can make assumptions like WMI will be unavailable. But uniting Not-Windows them under the banner of Unix seems superfluous and inaccurate. |
On another note. I believe adding automatic variables should require an RFC. I would suggest drafting an RFC and moving the conversation there. |
It's a matter of semantic directness: If I want to express that something should be done on any of the supported Unix-heritage platforms, I want to express that directly (positively, in this case): if ($IsUnix) ... PowerShell commendably already adheres to this principle in other areas: take the Additionally, on a largely hypothetical note: While (Conversely, adding support for a different type of Unix-heritage platform would extend the meaning of |
Re the name "Unix" and its applicability to Linux:
That you don't like the name is no reason to dispute the utility of the feature - it's a separate debate. A few pointers regarding the name, but it can be finalized if and once a consensus has been reached as to whether the feature is worth introducing: It is the case variant UNIX (all-caps) that is trademarked; I think that the term Unix to loosely refer to all platforms with a UNIX heritage is well-established - see https://en.wikipedia.org/wiki/Unix; to specifically address whether Linux should be considered a "Unix" system (from https://en.wikipedia.org/wiki/Unix-like#Categories):
These classifications are not an exact science. To me, something like |
Re the usefulness of the "Unix" abstraction and whether it warrants a direct expression in something like The variable Countless questions on Stack Overflow will tell you that there's a need for that. |
Let's not make this personal, OK? This isn't even about me. I personally don't care if Unix is used to refer to Linux. But, some people really do. I'm bring awareness to that fact. Since PowerShell is a Microsoft product, there is an image issue to consider when dealing with other communities. I'm cautioning against it for that reason alone. I don't have any personal stake in it. |
I agree. And I didn't. I merely pointed out a logical fallacy: That a feature shouldn't be given the specific name X is no argument against the feature itself. That's all I was trying to say.
It's commendable that you care about that and it is a debate worth having (I've already provided my input) - just separate from whether the feature should be introduced or not. |
Long term are there any plans to port PowerShell onto Unix (as opposed to Linux) platforms. If there is ven the chance of that happening then $IsUnix should be reserved for that case. |
@RichardSiddaway: UNIX® is a trademarked standard, not a specific OS.
A specific OS can be certified as UNIX®[-compliant]:
http://www.opengroup.org/certifications/unix SUS (the Single UNIX Specification) is synonymous with POSIX. Here's the list of the currently certified UNIX® systems. As you can see, macOS is a UNIX® platform, albeit conformant to an earlier version of the standard, UNIX 03 a.k.a. SUSv3 a.ka. POSIX:2001 (current is UNIX V7 a.k.a SUSv4 a.k.a POSIX:2008). As for Linux: From https://en.wikipedia.org/wiki/Single_UNIX_Specification#Non-registered_Unix-like_systems
In practice, most Linux distros are largely POSIX-compatible, and targeting a subset of the POSIX features is the key to portability. Knowing which specific POSIX features cannot be relied upon requires experience, but writing portable-across-Unix-like-platforms scripts is doable and desirable. |
I forgot about |
Let me try to summarize, and then I'll leave it be: Again, it comes down to having a direct expression of one's intent: If I want to target all supported Unix platforms as a group so as to write Unix-portable code (which I've hopefully demonstrated is a real thing), I want to be able to express that directly with something like Yes, it's easy enough to roll one's own - Having "Unix" as an abstract entity is also being discussed in the context of |
I don't believe this change would be trivial. https://github.com/search?q=language%3Apowershell+%24IsUnix&type=Code&utf8=%E2%9C%93 I believe for serious consideration, this should be moved to an RFC. |
Thanks for digging deeper. It's a fair concern, given the lack of a distinct namespace for automatic variables (sigh). Yes, making it read-only would definitely break scripts, but not making it read-only is an option (just like many existing automatic variables that should be read-only aren't, for fear of breaking things). What your results tell me, however, is that there is a need for such a variable; let's take the line from the Platypus repo, for instance: $global:IsUnix = $MyIsLinux -or $MyIsMacOS Below is the full list of distinct definitions, and all of them are variations of what [bool] $global:isUnix = [System.Environment]::OSVersion.Platform -eq [System.PlatformID]::Unix
IsUnix = $PSVersionTable.PSEdition -eq "Core" -and -not $IsWindows
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
$IsUnix # assigned via function is_unix() { $PSVersionTable.Platform -eq 'Unix' }
Set-Variable -Name IsUnix -Value $false -Scope Global # guarded by if ($PSVersionTable.PSVersion.Major -lt 6), so not a problem
$global:IsUnix = $MyIsLinux -or $MyIsMacOS If more people here indicate their support for the idea, I'm happy to write an RFC. |
Need? no. Desire, yes. Most of those mean |
"Need" as in: "This isn't built in, so I need to make my own." |
@PowerShell/powershell-committee discussed this and like the concept, however we would like community feedback on considering |
I prefer |
At the end of the day, I'm happy with either, as long as there is a way to positively express the commonality of Unix-like platforms. The caveat re
|
@mklement0 the committee wasn't sure if Linux is POSIX-certified (although we suspect Red Hat specifically probably is), but wanted to avoid any controversy of "Unix vs not-Unix" as macOS is Unix, but GNU is not Unix... |
I've quoted the Wikipedia page above, but if we go straight to the source, we'll see that no Linux system is certified (but macOS is), and that is unlikely to change: https://www.opengroup.org/openbrand/register/
Understood; an easy - if verbose - way out of this is |
Interesting discussion guys!! I just recently installed macOS in a VmWare VM and I never fully work on a Mac. Then, my first thoughts was that I was working in Linux with a GUI. Now I've learned is Unix. That's so cool! So, when is the next PowerShell Core Community Call? |
@mklement0 It seems that neither $IsPosix nor $IsUnix fits perfectly. Between those two, I think $IsUnix is more understandable to the majority of users. @MaximoTrinidad next call is next month May 18th! |
@mklement0 I think you're getting things a bit mixed up. Open Group certifies operating systems as UNIX not POSIX. POSIX is a family of standards created by the IEEE based on the various Unix variants. Linux is considered "mostly" POSIX-compliant, and with the LSB, will likely be completely so. More significantly, UNIX is a brand for specific operating systems whereas POSIX is a ABI specification. Saying
That is factually incorrect. Windows, through the POSIX subsystem, is certified as POSIX-compliant, as are a large number of operating systems. (A lot of vendors did this work in the late 90's to comply with FIPS 151-1). What Wndows is not is UNIX. |
Note that the suggestion for the variable name was
If there is concern about the trademark issue,
So I think that establishes that
I'll address the POSIX/Unix terminology question in a separate comment. |
The name doesn't have to be 100% accurate, just accurate enough that any Linux, Windows, or Mac user will be able to understand the variable's intent. No grouping is going to be that accurate either way.
What about Cygwin and WSL? Is it factually correct to call either one of them Unix or Linux?
|
To answer the rhetorical question first:
Yes to "Unix" in the sense of "Unix-like" (we needn't worry about "Linux" in the context of this discussion, but as an aside: WSL self-identifies as Linux ( With respect to Cygwin it is a moot point, however, because you cannot install PowerShell Core in it (as far as I'm aware; you can start the Windows PowerShell Core executable, but then you're simply running on Windows) With respect to WSL: I don't know if it's officially supported, but running PowerShell Core on WSL seems to work fine, at least the Ubuntu flavor.
"Unix" is a grouping. No one should expect it to refer to a specific OS these days. I agree that we don't have to be accurate - in fact, we cannot be. Because But, perhaps, as with the "Unix" / "UNIX®" distinction, there's also informal use of "Posix". Strictly speaking, POSIX® is a family of standards, and selective certification is possible. At the end of the day, if everyone's happy with Without the compliance confusion, I agree that it's helpful to reference POSIX as a de-facto near-common denominator (even though that is quite fuzzy in itself, without naming parts or versions). |
From my reading of this discussion (grumbles aside), it sounds like we have consensus on $IsPosix. So we can move forward on it now - right? |
Sounds good to me. From the department of more-than-you-ever-wanted-to-know:
The perhaps surprising thing is that while UNIX® certification encompasses compliance with a specific POSIX standard, it is distinct from POSIX® certification (with the latter seemingly of little real-world importance, given how few products are currently certified).
As stated above, the Open Group does both (in the case of POSIX jointly with IEEE).
The current POSIX standards include - but aren't limited to - an API specification, not an ABI specification - compatibility is only required at the source-code level, not at the binary level.
No, Windows is not currently POSIX-certified (and it's safe to assume won't ever be again). A brief history of POSIX on Windows:
|
After having read the thread again it seems there is still no conclusion. @SteveL-MSFT Should we therefore take the |
Then Linux is definitvely not in that game as it does not have any Unix heritage at all. |
It's not about heritage in a strict historical sense, it's about common, (quasi-)standardized behavior. From https://en.wikipedia.org/wiki/Linux#Development:
|
At this point, I think |
This issue has been marked as declined and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
On a side note: The automatic
$Is*
variables aren't universally loved due to "polluting" the global namespace, but it looks like they're here to stay.Platforms with Unix heritage have many commonalities, especially at higher levels of abstraction, so sometimes it is sufficient to distinguish Unix platforms as a group from Windows.
Thus, instead of having to use
$IsLinux -or $IsMacOS
or$PSVersionTable.Platform -eq 'Unix'
(yes,Unix
is reported on both macOS and Linux), it would be convenient to be able to say$IsUnix
.Update to clarify: The variable
$IsUnix
would not be for everyone: Its target audience are developers who need to develop portable-across-Unix-like-systems-but-not-Windows functionality.Note that the commonalities are reflected even at a lower level, namely in the CoreFX implementation: as of this writing, among the Unix-related classes, 50 are abstract (
*.Unix.cs
), 25 are macOS-specific (*.OSX.cs
), and 11 Linux-specific (*.Linux.cs
)Environment data
Written as of:
PowerShell Core v6.0.2
The text was updated successfully, but these errors were encountered: