POSIX 是什么？让我们听听 Richard Stallman 的诠释
GNU POSIX

> 
> 从计算机自由先驱的口中探寻操作系统兼容性标准背后的本质。
> 
> 
> 


![](/data/attachment/album/201908/13/231737robbwoss7p3p7jwo.jpg)


[POSIX](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/) 是什么？为什么如此重要？你可能在很多的技术类文章中看到这个术语，但往往会在探寻其本质时迷失在<ruby> 技术初始主义 <rt>  techno-initialisms </rt></ruby>的海洋或是<ruby> 以 X 结尾的行话 <rt>  jargon-that-ends-in-X </rt></ruby>中。我给 [Richard Stallman](https://stallman.org/) 博士（在黑客圈里面常称之为 RMS）发了邮件以探寻这个术语的起源及其背后的概念。


Richard Stallman 认为用 “开源” 和 “闭源” 来归类软件是一种错误的方法。Stallman 将程序分类为 <ruby> 尊重自由的 <rt>  freedom-respecting </rt></ruby>（“<ruby> 自由 <rt>  free </rt></ruby>” 或 “<ruby> 自由（西语） <rt>  libre </rt></ruby>”）和 <ruby> 践踏自由的 <rt>  freedom-trampling </rt></ruby>（“<ruby> 非自由 <rt>  non-free </rt></ruby>” 或 “<ruby> 专有 <rt>  proprietary </rt></ruby>”）。开源讨论通常会为了（用户）实际得到的<ruby> 优势/便利 <rt>  advantages </rt></ruby>考虑去鼓励某些做法，而非作为道德层面上的约束。


Stallman 在由其本人于 1984 年发起的<ruby> 自由软件运动 <rt>  The free software movement </rt></ruby>表明，不仅仅是这些 <ruby> 优势/便利 <rt>  advantages </rt></ruby> 受到了威胁。计算机的用户 <ruby> 理应得到 <rt>  deserve </rt></ruby> 计算机的控制权，因此拒绝被用户控制的程序即是 <ruby> 非正义 <rt>  injustice </rt></ruby>，理应被<ruby> 拒绝 <rt>  rejected </rt></ruby>和<ruby> 排斥 <rt>  eliminated </rt></ruby>。对于用户的控制权，程序应当给予用户 [四项基本自由](https://www.gnu.org/philosophy/free-sw.en.html)：


* 自由度 0：无论用户出于何种目的，必须可以按照用户意愿，自由地运行该软件。
* 自由度 1：用户可以自由地学习并修改该软件，以便按照自己的意愿进行计算。作为前提，用户必须可以访问到该软件的源代码。
* 自由度 2：用户可以自由地分发该软件的副本，以便可以帮助他人。
* 自由度 3：用户可以自由地分发该软件修改后的副本。借此，你可以让整个社区受益于你的改进。作为前提，用户必须可以访问到该软件的源代码。


### 关于 POSIX


**Seth:** POSIX 标准是由 [IEEE](https://www.ieee.org/) 发布，用于描述 “<ruby> 可移植操作系统 <rt>  portable operating system </rt></ruby>” 的文档。只要开发人员编写符合此描述的程序，他们生产的便是符合 POSIX 的程序。在科技行业，我们称之为 “<ruby> 规范 <rt>  specification </rt></ruby>” 或将其简写为 “spec”。就技术用语而言，这是可以理解的，但我们不禁要问是什么使操作系统 “可移植”？


**RMS:** 我认为是<ruby> 接口 <rt>  interface </rt></ruby>应该（在不同系统之间）是可移植的，而非任何一种*系统*。实际上，内部构造不同的各种系统都支持部分的 POSIX 接口规范。


**Seth:** 因此，如果两个系统皆具有符合 POSIX 的程序，那么它们便可以彼此假设，从而知道如何相互 “交谈”。我了解到 “POSIX” 这个简称是你想出来的。那你是怎么想出来的呢？它是如何就被 IEEE 采纳了呢？


**RMS:** IEEE 已经完成了规范的开发，但还没为其想好简练的名称。标题类似是 “可移植操作系统接口”，虽然我已记不清确切的单词。委员会倾向于将 “IEEEIX” 作为简称。而我认为那不太好。发音有点怪 - 听起来像恐怖的尖叫，“Ayeee！” - 所以我觉得人们反而会倾向于称之为 “Unix”。


但是，由于 <ruby> <a href="http://gnu.org">  GNU 并不是 Unix </a> <rt>  GNU’s Not Unix </rt></ruby>，并且它打算取代之，我不希望人们将 GNU 称为 “Unix 系统”。因此，我提出了人们可能会实际使用的简称。那个时候也没有什么灵感，我就用了一个并不是非常聪明的方式创造了这个简称：我使用了 “<ruby> 可移植操作系统 <rp>  （ </rp> <rt>  portable operating system </rt> <rp>  ） </rp></ruby>” 的首字母缩写，并在末尾添加了 “ix” 作为简称。IEEE 也欣然接受了。


**Seth:** POSIX 缩写中的 “操作系统” 是仅涉及 Unix 和类 Unix 的系统（如 GNU）呢？还是意图包含所有操作系统？


**RMS:** 术语 “操作系统” 抽象地说，涵盖了完全不像 Unix 的系统、完全和 POSIX 规范无关的系统。但是，POSIX 规范适用于大量类 Unix 系统；也只有这样的系统才适合 POSIX 规范。


**Seth:** 你是否参与审核或更新当前版本的 POSIX 标准？


**RMS:** 现在不了。


**Seth:** GNU Autotools 工具链可以使应用程序更容易移植，至少在构建和安装时如此。所以可以认为 Autotools 是构建可移植基础设施的重要一环吗？


**RMS:** 是的，因为即使在遵循 POSIX 的系统中，也存在着诸多差异。而 Autotools 可以使程序更容易适应这些差异。顺带一提，如果有人想助力 Autotools 的开发，可以发邮件联系我。


**Seth:** 我想，当 GNU 刚刚开始让人们意识到一个非 Unix 的系统可以从专有的技术中解放出来的时候，关于自由软件如何协作方面，这其间一定存在一些空白区域吧。


**RMS:** 我不认为有任何空白或不确定性。我只是照着 BSD 的接口写而已。


**Seth:** 一些 GNU 应用程序符合 POSIX 标准，而另一些 GNU 应用程序的 GNU 特定的功能，要么不在 POSIX 规范中，要么缺少该规范要求的功能。对于 GNU 应用程序 POSIX 合规性有多重要？


**RMS:** 遵循标准对于利于用户的程度很重要。我们不将标准视为权威，而是且将其作为可能有用的指南来遵循。因此，我们谈论的是<ruby> 遵循 <rt>  following </rt></ruby>标准而不是“<ruby> 遵守 <rt>  complying </rt></ruby>”。可以参考 <ruby> GNU 编码标准 <rt>  GNU Coding Standards </rt></ruby>中的 [非 GNU 标准](https://www.gnu.org/prep/standards/html_node/Non_002dGNU-Standards.html) 段落。


我们努力在大多数问题上与标准兼容，因为在大多数的问题上这最有利于用户。但也偶有例外。


例如，POSIX 指定某些实用程序以 512 字节为单位测量磁盘空间。我要求委员会将其改为 1K，但被拒绝了，说是有个<ruby> 官僚主义的规则 <rt>  bureaucratic rule </rt></ruby>强迫选用 512。我不记得有多少人试图争辩说，用户会对这个决定感到满意的。


由于 GNU 在用户的<ruby> 自由 <rt>  freedom </rt></ruby>之后的第二优先级，是用户的<ruby> 便利 <rt>  convenience </rt></ruby>，我们使 GNU 程序以默认 1K 为单位按块测量磁盘空间。


然而，为了防止竞争对手利用这点给 GNU 安上 “<ruby> 不合规 <rt>  noncompliant </rt></ruby>” 的骂名，我们实现了遵循 POSIX 和 ISO C 的可选模式，这种妥协着实可笑。想要遵循 POSIX，只需设置环境变量 `POSIXLY_CORRECT`，即可使程序符合 POSIX 以 512 字节为单位列出磁盘空间。如果有人知道实际使用 `POSIXLY_CORRECT` 或者 GCC 中对应的 `--pedantic` 会为某些用户提供什么实际好处的话，请务必告诉我。


**Seth:** 符合 POSIX 标准的自由软件项目是否更容易移植到其他类 Unix 系统？


**RMS:** 我认为是这样，但自上世纪 80 年代开始，我决定不再把时间浪费在将软件移植到 GNU 以外的系统上。我开始专注于推进 GNU 系统，使其不必使用任何非自由软件。至于将 GNU 程序移植到非类 GNU 系统就留给想在其他系统上运行它们的人们了。


**Seth:** POSIX 对于软件的自由很重要吗？


**RMS:** 本质上说，（遵不遵循 POSIX）其实没有任何区别。但是，POSIX 和 ISO C 的标准化确实使 GNU 系统更容易迁移，这有助于我们更快地实现从非自由软件中解放用户的目标。这个目标于上世纪 90 年代早期达成，当时Linux成为自由软件，同时也填补了 GNU 中内核的空白。


### POSIX 采纳 GNU 的创新


我还问过 Stallman 博士，是否有任何 GNU 特定的创新或惯例后来被采纳为 POSIX 标准。他无法回想起具体的例子，但友好地代我向几位开发者发了邮件。


开发者 Giacomo Catenazzi，James Youngman，Eric Blake，Arnold Robbins 和 Joshua Judson Rosen 对以前的 POSIX 迭代以及仍在进行中的 POSIX 迭代做出了回应。POSIX 是一个 “<ruby> 活的 <rt>  living </rt></ruby>” 标准，因此会不断被行业专业人士更新和评审，许多从事 GNU 项目的开发人员提出了对 GNU 特性的包含。


为了回顾这些有趣的历史，接下来会罗列一些已经融入 POSIX 的流行的 GNU 特性。


#### Make


一些 GNU **Make** 的特性已经被 POSIX 的 `make` 定义所采用。相关的 [规范](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html) 提供了从现有实现中借来的特性的详细归因。


#### Diff 和 patch


[diff](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html) 和 [patch](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/patch.html) 命令都直接从这些工具的 GNU 版本中引进了 `-u` 和 `-U` 选项。


#### C 库


POSIX 采用了 GNU C 库 **glibc** 的许多特性。<ruby> 血统 <rt>  Lineage </rt></ruby>一时已难以追溯，但 James Youngman 如是写道：



> 
> “我非常确定 GCC 首创了许多 ISO C 的特性。例如，**\_Noreturn** 是 C11 中的新特性，但 GCC-1.35 便具有此功能（使用 `volatile` 作为声明函数的修饰符）。另外尽管我不确定，GCC-1.35 支持的可变长度数组似乎与现代 C 中的（<ruby> 柔性数组 <rt>  conformant array </rt></ruby>）非常相似。”
> 
> 
> 


Giacomo Catenazzi 援引 Open Group 的 [strftime](https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html) 文章，并指出其归因：“这是基于某版本 GNU libc 的 `strftime()` 的特性。”


Eric Blake 指出，对于 `getline()` 和各种基于语言环境的 `*_l()` 函数，GNU 绝对是这方面的先驱。


Joshua Judson Rosen 补充道，他清楚地记得，在全然不同的操作系统的代码中奇怪地目睹了熟悉的 GNU 式的行为后，对 `getline()` 函数的采用给他留下了深刻的印象。


“等等……那不是 GNU 特有的吗？哦，显然已经不再是了。”


Rosen 向我指出了 [getline 手册页](http://man7.org/linux/man-pages/man3/getline.3.html) 中写道：



> 
> `getline()` 和 `getdelim()` 最初都是 GNU 扩展。在 POSIX.1-2008 中被标准化。
> 
> 
> 


Eric Blake 向我发送了一份其他扩展的列表，这些扩展可能会在下一个 POSIX 修订版中添加（代号为 Issue 8，大约在 2021 年前后）：


* [ppoll](http://austingroupbugs.net/view.php?id=1263)
* [pthread\_cond\_clockwait et al.](http://austingroupbugs.net/view.php?id=1216)
* [posix\_spawn\_file\_actions\_addchdir](http://austingroupbugs.net/view.php?id=1208)
* [getlocalename\_1](http://austingroupbugs.net/view.php?id=1220)
* [reallocarray](http://austingroupbugs.net/view.php?id=1218)


### 关于用户空间的扩展


POSIX 不仅为开发人员定义了函数和特性，还为用户空间定义了标准行为。


#### ls


`-A` 选项会排除来自 `ls` 命令结果中的符号 `.`（代表当前位置）和 `..`（代表上一级目录）。它被 POSIX 2008 采纳。


#### find


`find` 命令是一个<ruby> 特别的 <rp>  （ </rp> <rt>  ad hoc </rt> <rp>  ） </rp></ruby> [for 循环](https://opensource.com/article/19/6/how-write-loop-bash) 工具，也是 [<ruby> 并行 <rt>  parallel </rt></ruby>](https://opensource.com/article/18/5/gnu-parallel) 处理的出入口。


一些从 GNU 引入到 POSIX 的<ruby> 便捷操作 <rt>  conveniences </rt></ruby>，包括 `-path` 和 `-perm` 选项。


`-path` 选项帮你过滤与文件系统路径模式匹配的搜索结果，并且从 1996 年（根据 `findutil` 的 Git 仓库中最早的记录）GNU 版本的 `find` 便可使用此选项。James Youngman 指出 [HP-UX](https://www.hpe.com/us/en/servers/hp-ux.html) 也很早就有这个选项，所以究竟是 GNU 还是 HP-UX 做出的这一创新（抑或两者兼而有之）无法考证。


`-perm` 选项帮你按文件权限过滤搜索结果。这在 1996 年 GNU 版本的 `find` 中便已存在，随后被纳入 POSIX 标准 “IEEE Std 1003.1,2004 Edition” 中。


`xargs` 命令是 `findutils` 软件包的一部分，1996 年的时候就有一个 `-p` 选项会将 `xargs` 置于交互模式（用户将被提示是否继续），随后被纳入 POSIX 标准 “IEEE Std 1003.1, 2004 Edition” 中。


#### Awk


GNU awk（即 `/usr/bin` 目录中的 `gawk` 命令，可能也是符号链接 `awk` 的目标地址）的维护者 Arnold Robbins 说道，`gawk` 和 `mawk`（另一个GPL 的 `awk` 实现）允许 `RS`（记录分隔符）是一个正则表达式，即这时 `RS` 的长度会大于 1。这一特性还不是 POSIX 的特性，但有 [迹象表明它即将会是](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html)：



> 
> NUL 在扩展正则表达式中产生的未定义行为允许 GNU `gawk` 程序未来可以扩展以处理二进制数据。
> 
> 
> 使用多字符 RS 值的未指定行为是为了未来可能的扩展，它是基于用于记录分隔符（RS）的扩展正则表达式的。目前的历史实现为采用该字符串的第一个字符而忽略其他字符。
> 
> 
> 


这是一个重大的增强，因为 `RS` 符号定义了记录之间的分隔符。可能是逗号、分号、短划线、或者是任何此类字符，但如果它是字符*序列*，则只会使用第一个字符，除非你使用的是 `gawk` 或 `mawk`。想象一下这种情况，使用省略号（连续的三个点）作为解析 IP 地址文档的分隔记录，只是想获取在每个 IP 地址的每个点处解析的结果。


[mawk](https://invisible-island.net/mawk/) 首先支持这个功能，但是几年来没有维护者，留下来的火把由 `gawk` 接过。（`mawk` 已然获得了一个新的维护者，可以说是大家薪火传承地将这一特性推向共同的预期值。）


### POSIX 规范


总的来说，Giacomo Catenzzi 指出，“……因为 GNU 的实用程序使用广泛，而且许多其他的选项和行为又对标规范。在 shell 的每次更改中，Bash 都会（作为一等公民）被用作比较。” 当某些东西被纳入 POSIX 规范时，无需提及 GNU 或任何其他影响，你可以简单地认为 POSIX 规范会受到许多方面的影响，GNU 只是其中之一。


共识是 POSIX 存在的意义所在。一群技术人员共同努力为了实现共同规范，再分享给数以百计各异的开发人员，经由他们的赋能，从而实现软件的独立性，以及开发人员和用户的自由。




---


via: <https://opensource.com/article/19/7/what-posix-richard-stallman-explains>


作者：[Seth Kenlon](https://opensource.com/users/seth) 选题：[lujun9972](https://github.com/lujun9972) 译者：[martin2011qi](https://github.com/martin2011qi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
What is [POSIX](https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/), and why does it matter? It's a term you've likely seen in technical writing, but it often gets lost in a sea of techno-initialisms and jargon-that-ends-in-X. I emailed Dr. [Richard Stallman](https://stallman.org/) (better known in hacker circles as RMS) to find out more about the term's origin and the concept behind it.

Richard Stallman says "open" and "closed" are the wrong way to classify software. Stallman classifies programs as *freedom-respecting* ("free" or "libre") and *freedom-trampling* ("non-free" or "proprietary"). Open source discourse typically encourages certain practices for the sake of practical advantages, not as a moral imperative.

The free software movement, which Stallman launched in 1984, says more than *advantages* are at stake. Users of computers *deserve* control of their computing, so programs denying users control are an injustice to be rejected and eliminated. For users to have control, the program must give them the [four essential freedoms](https://www.gnu.org/philosophy/free-sw.en.html):

- The freedom to run the program as you wish, for any purpose (freedom 0).
- The freedom to study how the program works and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.
- The freedom to redistribute copies so you can help others (freedom 2).
- The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.

## About POSIX

**Seth:** The POSIX standard is a document released by the [IEEE](https://www.ieee.org/) that describes a "portable operating system." As long as developers write programs to match this description, they have produced a POSIX-compliant program. In the tech industry, we call this a "specification" or "spec" for short. That's mostly understandable, as far as tech jargon goes, but what makes an operating system "portable"?

**RMS:** I think it was the *interface* that was supposed to be portable (among systems), rather than any one *system*. Indeed, various systems that are different inside do support parts of the POSIX interface spec.

**Seth:** So if two systems feature POSIX-compliant programs, then they can make assumptions about one another, enabling them to know how to "talk" to one another. I read that it was you who came up with the name "POSIX." How did you come up with the term, and how was it adopted by the IEEE?

**RMS:** The IEEE had finished developing the spec but had no concise name for it. The title said something like "portable operating system interface," though I don't remember the exact words. The committee put on "IEEEIX" as the concise name. I did not think that was a good choice. It is ugly to pronounce—it would sound like a scream of terror, "Ayeee!"—so I expected people would instead call the spec "Unix."

Since [GNU's Not Unix](http://gnu.org), and it was intended to replace Unix, I did not want people to call GNU a "Unix system." I, therefore, proposed a concise name that people might actually use. Having no particular inspiration, I generated a name the unclever way: I took the initials of "portable operating system" and added "ix." The IEEE adopted this eagerly.

**Seth:** Does "operating system" in the POSIX acronym refer only to Unix and Unix-like systems such as GNU, or is the intent to encompass all operating systems?

**RMS:** The term "operating system," in the abstract, covers systems that are not at all like Unix, not at all close to the POSIX spec. However, the spec is meant for systems that are a lot like Unix; only such systems will fit the POSIX spec.

**Seth:** Are you involved in reviewing or updating the current POSIX standards?

**RMS:** Not now.

**Seth:** The GNU Autotools toolchain does a lot to make applications easier to port, at least in terms of when it comes time to build and install. Is Autotools an important part of building a portable infrastructure?

**RMS:** Yes, because even among systems that follow POSIX, there are lots of little differences. The Autotools make it easier for a program to adapt to those differences. By the way, if anyone wants to help in the development of the Autotools, please email me.

**Seth:** I imagine, way back when GNU was just starting to make people realize that a (not)Unix liberated from proprietary technology was possible, there must have been a void of clarity about how free software could possibly work together.

**RMS:** I don't think there was any void or any uncertainty. I was simply going to follow the interfaces of BSD.

**Seth:** Some GNU applications are POSIX-compliant, while others have GNU-specific features either not in the POSIX spec or lack features required by the spec. How important is POSIX compliance to GNU applications?

**RMS:** Following a standard is important to the extent it serves users. We do not treat a standard as an authority, but rather as a guide that may be useful to follow. Thus, we talk about following standards rather than "complying" with them. See the section [Non-GNU Standards](https://www.gnu.org/prep/standards/html_node/Non_002dGNU-Standards.html) in the GNU Coding Standards.

We strive to be compatible with standards on most issues because, on most issues, that serves users best. But there are occasional exceptions.

For instance, POSIX specifies that some utilities measure disk space in units of 512 bytes. I asked the committee to change this to 1K, but it refused, saying that a bureaucratic rule compelled the choice of 512. I don't recall much attempt to argue that users would be pleased with that decision.

Since GNU's second priority, after users' freedom, is users' convenience, we made GNU programs measure disk space in blocks of 1K by default.

However, to defend against potential attacks by competitors who might claim that this deviation made GNU "noncompliant," we implemented optional modes that follow POSIX and ISO C to ridiculous extremes. For POSIX, setting the environment variable POSIXLY_CORRECT makes programs specified by POSIX list disk space in terms of 512 bytes. If anyone knows of a case of an actual use of POSIXLY_CORRECT or its GCC counterpart **--pedantic** that provides an actual benefit to some user, please tell me about it.

**Seth:** Are POSIX-compliant free software projects easier to port to other Unix-like systems?

**RMS:** I suppose so, but I decided in the 1980s not to spend my time on porting software to systems other than GNU. I focused on advancing the GNU system towards making it unnecessary to use any non-free software and left the porting of GNU programs to non-GNU-like systems to whoever wanted to run them on those systems.

**Seth:** Is POSIX important to software freedom?

**RMS:** At the fundamental level, it makes no difference. However, standardization by POSIX and ISO C surely made the GNU system easier to migrate to, and that helped us advance more quickly towards the goal of liberating users from non-free software. That was achieved in the early 1990s, when Linux was made free software and then filled the kernel-shaped gap in GNU.

## GNU innovations adopted by POSIX

I also asked Dr. Stallman whether any GNU-specific innovations or conventions had later become adopted as a POSIX standard. He couldn't recall specific examples, but kindly emailed several developers on my behalf.

Developers Giacomo Catenazzi, James Youngman, Eric Blake, Arnold Robbins, and Joshua Judson Rosen all responded with memories of previous POSIX iterations as well as ones still in progress. POSIX is a "living" standard, so it's being updated and reviewed by industry professionals continuously, and many developers who work on GNU projects propose the inclusion of GNU features.

For the sake of historical interest, here' are some popular GNU features that have made their way into POSIX.

### Make

Some GNU **Make** features have been adopted into POSIX's definition of **make**. The relevant [specification](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html) provides detailed attribution for features borrowed from existing implementations.

### Diff and patch

Both the ** diff** and

**commands have gotten**

[patch](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/patch.html)**-u**and

**-U**options added directly from GNU versions of those tools.

### C library

Many features of the GNU C library, **glibc**, have been adopted in POSIX. Lineage is sometimes difficult to trace, but James Youngman wrote:

"I'm pretty sure there are a number of features of ISO C which were pioneered by GCC. For example,

_Noreturnis new in C11, but GCC-1.35 had this feature (one used thevolatilemodifier on a function declaration). Also—though I'm not certain about this—GCC-1.35 supported Arrays of Variable Length which seem to be very similar to modern C's conformant arrays."

Giacomo Catenazzi cites the Open Group's [ strftime article](https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html), pointing to this attribution: "This is based on a feature in some versions of GNU libc's

**strftime()**."

Eric Blake notes that the **getline()** and various ***_l()** locale-based functions were definitely pioneered by GNU.

Joshua Judson Rosen adds to this, saying he clearly remembers being impressed by the adoption of **getline** functions after witnessing strangely familiar GNU-like behavior from code meant for a different OS entirely.

"Wait…that's GNU-specific… isn't it? Oh—not anymore, apparently."

Rosen pointed me to the [ getline man page](http://man7.org/linux/man-pages/man3/getline.3.html), which says:

Both

getline()andgetdelim()were originally GNU extensions. They were standardized in POSIX.1-2008.

Eric Blake sent me a list of other extensions that may be added in the next POSIX revision (codenamed Issue 8, currently due around 2021):

## Userspace extensions

POSIX doesn't just define functions and features for developers. It defines standard behavior for userspace as well.

### ls

The **-A** option is used to exclude the **.** (representing the current location) and **..** (representing the opportunity to go back one directory) notation from the results of an **ls** command. This was adopted for POSIX 2008.

### find

The **find** command is a useful tool for ad hoc [ for loops](https://opensource.com/article/19/6/how-write-loop-bash) and as a gateway into

[parallel](https://opensource.com/article/18/5/gnu-parallel)processing.

A few conveniences made their way from GNU to POSIX, including the **-path** and **-perm** options.

The **-path** option lets you filter search results matching a filesystem path pattern and was available in GNU's version of **find** since before 1996 (the earliest record in **findutil**'s Git repository). James Youngman notes that [HP-UX](https://www.hpe.com/us/en/servers/hp-ux.html) also had this option very early on, so whether it's a GNU or an HP-UX innovation (or both) is uncertain.

The **-perm** option lets you filter search results by file permission. This was in GNU's version of **find** by 1996 and arrived later in the POSIX standard "IEEE Std 1003.1, 2004 Edition."

The **xargs** command, part of the **findutils** package, had a **-p** option to put **xargs** into an interactive mode (the user is prompted whether to continue or not) by 1996, and it arrived in POSIX in "IEEE Std 1003.1, 2004 Edition."

### Awk

Arnold Robbins, the maintainer of GNU **awk** (the **gawk** command in your **/usr/bin** directory, probably the destination of the symlink **awk**), says that **gawk** and **mawk** (another GPL **awk** implementation) allow **RS** to be a regular expression, which is the case when **RS** has a length greater than 1. This isn't a feature in POSIX yet, but there's an [indication that it will be](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html):


The undefined behavior resulting from NULs in extended regular expressions allows future extensions for the GNU gawk program to process binary data.

The unspecified behavior from using multi-character RS values is to allow possible future extensions based on extended regular expressions used for record separators. Historical implementations take the first character of the string and ignore the others.

This is a significant enhancement because the **RS** notation defines a separator between records. It might be a comma or a semicolon or a dash or any such character, but if it's a *sequence* of characters, then only the first character is used unless you're working in **gawk** or **mawk**. Imagine parsing a document of IP addresses with records separated by an ellipsis (three dots in a row), only to get back results parsed at every dot in every IP address.

** Mawk** supported the feature first, but it was without a maintainer for several years, leaving

**gawk**to carry the torch. (

**Mawk**has since gained a new maintainer, so arguably credit can be shared for pushing this feature into the collective expectation.)

## The POSIX spec

In general, Giacomo Catenzzi points out, "…because GNU utilities were used so much, a lot of other options and behaviors were aligned. At every change in shell, Bash is used as comparison (as a first-class citizen)." There's no requirement to cite GNU or any other influence when something is rolled into the POSIX spec, and it can safely be assumed that influences to POSIX come from many sources, with GNU being only one of many.

The significance of POSIX is consensus. A group of technologists working together toward common specifications to be shared by hundreds of uncommon developers lends strength to the greater movement toward software independence and developer and user freedom.

## 4 Comments