惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园_首页
宝玉的分享
宝玉的分享
S
SegmentFault 最新的问题
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
美团技术团队
IT之家
IT之家
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
博客园 - 叶小钗
M
MIT News - Artificial intelligence
B
Blog RSS Feed
有赞技术团队
有赞技术团队
Y
Y Combinator Blog

seize the dev

Self-Hosted Dynamic DNS Will Software Engineering Survive? Why is the Gmail app 700 MB? Bits of Open-Source in 2025 Parsing JSON in Forty Lines of Awk A Tricky Floating-Point Calculation Improving Date Formatting Performance in Node.js Installing FreeBSD on Oracle Cloud A Simple Setup for C and C++ How to Break Software
Unix is not Linux
Mohamed Akram · 2022-08-21 · via seize the dev

Too often on the internet, tutorials and guides are written of POSIX and Unix tools that implicitly assume a Linux installation, and more specifically a GNU-based one. This has many implications when it comes to everything from the behavior of the shell, its utilities, and even the C standard library. While the dominance of Linux might mean that one can ignore this distinction, it is still useful to be aware of it. I’ve outlined some of the more prominent discrepancies below.

Bash is not the standard shell

The default shell that is present on all Unix systems is sh, not bash. The language used in the portable sh shell is described in the POSIX standard. However, on many Linux systems sh is linked to bash - this makes bash operate in a more compatible way with the standard, but still allows certain bash features that may not work on other systems. When in doubt, refer to the standard.

Long options are not Unix

Many utilities accept both a long option, eg. grep --count with a double hyphen, in addition to a short option, eg. grep -c. The former is a GNU invention, and they generally do not exist on other systems, such as BSDs. In fact, the standard getopts utility, and corresponding getopt C function only support the short style.

Make isn’t GNU make

The version of make specified by POSIX is much more limited than the GNU version. This one is harder to deal with as the specification is lacking in many aspects, particularly any kind of logical or conditional operators. You can workaround this by moving some logic to a configure script that generates another Makefile that is then included by the main one. Further, the BSD makes have a completely different syntax than the GNU one for things like conditionals. Luckily, if your focus is on macOS and Linux only, you can get away with depending on GNU features as macOS’s make is based on the GNU one.

The C compiler is not GCC

This is related to the previous point, as it often comes up in Makefiles. When referring to the C compiler in that context, it is better to use the implicit $(CC) variable, and when compiling C++ code, to use the $(CXX) variable. Most BSD systems have now switched to Clang as the default compiler and do not provide a gcc binary. When referring to the C and C++ compilers outside of Makefiles, the cc and c++ commands are reliable and work across systems.

GNU is not Linux

This is slightly different, but even GNU interfaces are not necessarily the ones present on a Linux system. The Alpine Linux distribution for example, popular as a base in Docker containers due to its light weight, forgoes the GNU C Library for musl, and uses BusyBox instead of the GNU utilities. Therefore, one would be well advised to try to stick to portable interfaces even if targeting solely Linux systems.

Unix is not UNIX

Finally, even Unix is not UNIX. The latter is a trademark that requires certification by The Open Group. Certified operating systems, the most well-known of which is macOS, are guaranteed to follow the UNIX specification. That said, most Unix-like operating systems, including the BSDs, as well as the GNU tools make a strong effort to stick to the standard as much as possible.