Skip to content

Consider introducing $IsUnix as an abstraction over $IsMacOS and $IsLinux #6518

Closed

Description

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

Activity

  1. added
    Issue-Enhancement
    on Mar 27, 2018
  2. vexx32 commented on Mar 28, 2018

    @vexx32
    Collaborator

    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?

  3. SteveL-MSFT commented on Mar 28, 2018

    @SteveL-MSFT
    Member

    Rain Sallow (/u/ta11ow) (@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 interop namespace, but that would be additive and not replacing these variables.

    I would agree there is utility in having $IsUnix

  4. changed the title [-]Consider introducing $IsUnix as an abstraction over $IsMacOs and $IsLinux[/-] [+]Consider introducing $IsUnix as an abstraction over $IsMacOS and $IsLinux[/+] on Mar 28, 2018
  5. RichardSiddaway commented on Mar 28, 2018

    @RichardSiddaway

    Struggling to see the utility of this. We already have $IsWindows so
    ! $IsWindows
    effectively gives the same thing.
    seems to be an addition for sake of an addition rather than a practical expansion of functionality

  6. markekraus commented on Mar 28, 2018

    @markekraus
    Contributor

    I'm opposed to this for several reasons. The first of which RichardSiddaway has already covered regarding !$IsWindows.

    The second issue I take is with using Unix on Linux and macOS:

    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 Unix was used to distinguish more UNIX-like operating systems from Linux distributions. There are certain assumptions about locations, APIs, binaries, and devices that come with Unix-like operating systems that are not applicable to Linux distributions. Using Unix to include Linux could be confusing should we ever need to make the distinction between Linux-like and Unix-like.

    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 $IsUnix practically useless, IMO. Yes, some people do quite a bit of work to make their macOS more like Linux distributions, but out of the box they are are more distinct. The same can be said about the $IsLinux and the distinctive ecosystems within distribution and clone silos. However, $IsLinux does serve as a Not-Windows-or-macOS pretty well.

    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.

  7. markekraus commented on Mar 28, 2018

    @markekraus
    Contributor

    On another note. I believe adding automatic variables should require an RFC. I would suggest drafting an RFC and moving the conversation there.

  8. mklement0 commented on Mar 28, 2018

    @mklement0
    ContributorAuthor

    RichardSiddaway:

    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 -contains and -notcontains operator pair, as one example. Yes, -contains in combination with -not is technically enough, but -notcontains is a more succinct and direct expression of the intent.

    Additionally, on a largely hypothetical note: While ! $IsWindows is currently the equivalent of the proposed $IsUnix, that would change if support for a new, different platform type were to be introduced in the future.

    (Conversely, adding support for a different type of Unix-heritage platform would extend the meaning of $IsUnix, though presumably in a more predictable manner (quasi-POSIX as the common denominator).)

  9. mklement0 commented on Mar 28, 2018

    @mklement0
    ContributorAuthor

    Mark Kraus (@markekraus):

    Re the name "Unix" and its applicability to Linux:

    First, the usage is contentious to the point of being inflammatory in some circles.

    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):

    Dennis Ritchie, one of the original creators of Unix, expressed his opinion that Unix-like systems such as Linux are de facto Unix systems.[12]

    These classifications are not an exact science. To me, something like $IsUnixLike sounds like overkill and, given the presence of $IsMacOS and $IsLinux, no one should be tempted to infer that $IsUnix was chosen out of ignorance of the fact that "Unix" isn't a single, specific OS.

  10. mklement0 commented on Mar 28, 2018

    @mklement0
    ContributorAuthor

    Mark Kraus (@markekraus):

    Re the usefulness of the "Unix" abstraction and whether it warrants a direct expression in something like $IsUnix:

    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.

    Countless questions on Stack Overflow will tell you that there's a need for that.
    (And I've personally spent years answering questions about how to make commands / POSIX-like shell scripts run on both macOS and Linux (and others).)

  11. markekraus commented on Mar 28, 2018

    @markekraus
    Contributor

    Michael Klement (@mklement0)

    That you don't like the name is no reason to dispute the utility of the feature - it's a separate debate.

    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.

  12. mklement0 commented on Mar 28, 2018

    @mklement0
    ContributorAuthor

    Let's not make this personal, OK?

    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.

    Since PowerShell is a Microsoft product, there is an image issue to consider when dealing with other communities.

    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.

  13. RichardSiddaway commented on Mar 28, 2018

    @RichardSiddaway

    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.
    If its used as a bucket term for Linux and mac then the confusion when PowerShell on Unix arrives would be spectacular

  14. mklement0 commented on Mar 28, 2018

    @mklement0
    ContributorAuthor

    RichardSiddaway: UNIX® is a trademarked standard, not a specific OS.

    Learn about UNIX®, an Open Group standard ...

    http://opengroup.org/unix

    A specific OS can be certified as UNIX®[-compliant]:

    Only systems that are fully compliant and certified according to the Single UNIX Specification are qualified to use the UNIX® trademark.

    http://www.opengroup.org/certifications/unix

    SUS (the Single UNIX Specification) is synonymous with POSIX.
    These are abstract standards that a certified OSs must comply with.

    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

    • "Vendors of Unix-like systems such as Linux and FreeBSD do not typically certify their distributions" and "and do not install [the] full [set of] POSIX utilities by default."

    • But (emphasis added): "For Linux, the Linux Standard Base was formed in 2001 as an attempt to standardize the internal structures of Linux-based systems for increased compatibility. It is based on the POSIX specifications, the Single UNIX Specification, and other open standards, and also extends them in several areas; but there are some conflicts between the LSB and The POSIX standards."


    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.

  15. SteveL-MSFT commented on Mar 28, 2018

    @SteveL-MSFT
    Member

    I forgot about !$Windows which I agree covers the functional aspect. Unless there's another platform we support in the future that is not "Unix" and also not Windows, I rescind my support of $IsUnix.

  16. 15 remaining items

  17. BrucePay commented on Apr 27, 2018

    @BrucePay
    Collaborator

    Michael Klement (@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 $IsUNIX is claiming that the OS is UNIX which is likely false and in violation of the Open Group trademark. $IsPosix simply says the the platform supports some portion of the POSIX ABI.

    Factually, only macOS is a POSIX-certified platform.

    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.

  18. mklement0 commented on Apr 27, 2018

    @mklement0
    ContributorAuthor

    Saying $IsUNIX is claiming that the OS is UNIX which is likely false and in violation of the Open Group trademark

    Note that the suggestion for the variable name was $IsUnix (note the casing).

    • The name of the trademark, as stated earlier, is "UNIX®" - all-uppercase.

    • By contrast, "Unix" is not trademarked, and these days is widely understood to be a shorthand for "Unix-like", meaning a loose term to refer to platforms with either an AT&T Unix heritage (in terms of source code) or behavior similar to the original AT&T Unix.

    If there is concern about the trademark issue, $IsUnixLike offers a way out, but it feels clumsy - and also frowned upon by the owners of the trademark: "They do not approve of the construction "Unix-like", and consider it a misuse of their trademark." (see previous link)

    Linux is considered "mostly" POSIX-compliant, and with the LSB, will likely be completely so.

    It is based on the POSIX specifications, the Single UNIX Specification, and other open standards, and also extends them in several areas; but there are some conflicts between the LSB and The POSIX standards."

    • The same source also states: "very few Linux systems can be configured to be completely conformant."

    So I think that establishes that $IsPosix is factually incorrect.

    $IsPosixLike could work, but by your own reasoning, wouldn't that mean it should return $True even on Windows? That would certainly make the variable pointless.

    I'll address the POSIX/Unix terminology question in a separate comment.

  19. dragonwolf83 commented on Apr 27, 2018

    @dragonwolf83

    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.

    IsUnix alongside IsLinux, IsMacOs, and IsWindows is confusing. 3 of them are specific OS Platforms. There is no grouping. Now you add another OS Platform and then decide to group it for Linux and macOS. What if I thought that IsUnix meant any BSD-derivative of Unix, the Unix Clones instead of Linux?

    What about Cygwin and WSL? Is it factually correct to call either one of them Unix or Linux?

    IsPosix, the intent is much more clear. This is for any OS or Subsystem that implements the POSIX Standard. It seems to be generally understood that while Linux and others are not POSIX-certified, that they are implementing enough of the standard to be compliant for most use cases. It is much more accurate of a term since it is referencing a Standard and not an OS Platform. It covers the Cygwin and WSL use cases, alongside macOS, BSD, and Linux.

  20. mklement0 commented on Apr 27, 2018

    @mklement0
    ContributorAuthor

    Troy Campbell (@dragonwolf83):

    To answer the rhetorical question first:

    What about Cygwin and WSL? Is it factually correct to call either one of them Unix or Linux?

    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 (uname)), though you'd want to make clear that they're emulation environments with limitations.

    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.

    There is no grouping.

    "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 $IsPosix references an actual standard - trademarked as POSIX® - my concern was that it suggests an unwarranted accuracy (unlike $IsUnix).

    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.
    There is no the POSIX® standard, but there are parts that matter in the context of PowerShell.
    (I'll cover that in a separate comment.)

    At the end of the day, if everyone's happy with $IsPosix and understands it to mean quasi-POSIX® rather than certified compliance, that's fine.

    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).

  21. BrucePay commented on Apr 27, 2018

    @BrucePay
    Collaborator

    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?

  22. mklement0 commented on Apr 28, 2018

    @mklement0
    ContributorAuthor

    Bruce Payette (@BrucePay):

    Sounds good to me.

    From the department of more-than-you-ever-wanted-to-know:

    • POSIX® is a family of certifications, jointly awarded by the Open Group and IEEE (the certification authority is the former, the license authority the latter).

      • Currently, certification can be obtained for 4 distinct standards, subdivided into 2 real-time-OS standards distinguished by system size (1003.13 PSE52 and 1003.13 PSE52), and a non-real-time standard in 2 publication-year editions (1003.1 2016 and 1003.1 2003)

      • All POSIX standards mandate portability at the source-code level.

      • Only the 1003.1 (non-real-time) standards include standardization of a "command interpreter (or "shell"), and common utility programs" (volume Shell and Utilities).

      • The current list of certified products has surprisingly few entries - presumably, manufacturers go for the UNIX® certification instead.

      • Certification can be obtained without signing the trademark-licensing agreement, but only signing the latter entitles to use of the POSIX® trademark.

    • The UNIX® trademark, awarded by the Open Group, is awarded based on compliance with the SUS (Single Unix Specification).

    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).


    Open Group certifies operating systems as UNIX not POSIX

    As stated above, the Open Group does both (in the case of POSIX jointly with IEEE).

    POSIX is a ABI specification.

    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.

    Windows, through the POSIX subsystem, is certified as POSIX-compliant, as are a large number of operating systems.

    No, Windows is not currently POSIX-certified (and it's safe to assume won't ever be again).
    (Unix-like platforms aren't technically POSIX-certified: some went for UNIX-certification, which, however implies POSIX compliance, as detailed above.)

    A brief history of POSIX on Windows:

  23. SteveL-MSFT commented on May 2, 2018

    @SteveL-MSFT
    Member
  24. bergmeister commented on Jul 16, 2019

    @bergmeister
    Contributor

    After having read the thread again it seems there is still no conclusion. Steve Lee (@SteveL-MSFT) Should we therefore take the Commitee-Reviewed tag off?

  25. removed
    Committee-Reviewed
    on Jul 24, 2019
  26. michael-o commented on Nov 17, 2022

    @michael-o

    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.

    Then Linux is definitvely not in that game as it does not have any Unix heritage at all.

  27. mklement0 commented on Nov 17, 2022

    @mklement0
    ContributorAuthor

    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:

    Linux systems adhere to POSIX,[88] SUS,[89] LSB, ISO, and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.[90][91]

  28. SteveL-MSFT commented on Nov 22, 2022

    @SteveL-MSFT
    Member

    At this point, I think !$IsWindows is sufficient and we no longer need to keep this issue open

  29. added
    Resolution-Declined
    on Nov 22, 2022
  30. ghost closed this as completedon Nov 23, 2022
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

    Issue-EnhancementResolution-Declined

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions