From e5cf62736ce5fd6aede41481938b4ed4bb648ee8 Mon Sep 17 00:00:00 2001 From: Deven Blake Date: Fri, 6 Aug 2021 15:17:42 -0400 Subject: [PATCH] posix true --- homepage/index.html | 3 +- homepage/knowledge/true.html | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 homepage/knowledge/true.html diff --git a/homepage/index.html b/homepage/index.html index ae8c326..40b9738 100644 --- a/homepage/index.html +++ b/homepage/index.html @@ -13,7 +13,7 @@ trinity dot moe - + @@ -72,6 +72,7 @@ I'm vaccinated against COVID-19. Are you? /thegame; knowledge: NetBSD; +true(1); shilling: #stickers

diff --git a/homepage/knowledge/true.html b/homepage/knowledge/true.html new file mode 100644 index 0000000..86a8730 --- /dev/null +++ b/homepage/knowledge/true.html @@ -0,0 +1,72 @@ + + + + + + + + + +true(1) + + +

~ Return to the rest of the site

+ + + +

POSIX true(1)

+

updated 2021-08-06

+
+

+true(1) is a tool that only quits silently with an exit status of 0. +Similarly, false(1) is a tool that only quits silently with an exit status of 1. +Recognizing arguments, printing to standard output, reading from standard input, or otherwise exiting with any other status of 0, is a violation of the POSIX specification for true(1). +These utilities find use in shell scripting, which, though extremely relevant to these utilities, is beyond the scope of this article. +

+

+Because true(1)'s required functionality is so simple a POSIX-compliant implementation is a one-liner in most languages, so long as you're willing to make an exception in your code styling. +For example, in C: +

+

+int main(void) { return 0; }
+
+

+Because executing an empty shellscript file will in most shells do nothing and return an exit status of 0, technically an empty shellscript file is a POSIX-compliant true(1) implementation in 0 bytes. +However (TODO) it's to me unknown whether this is implementation-specific or POSIX-specified. +The usual implementation in POSIX shell is also a one-liner if you ignore the shebang: +

+

+#!/bin/sh
+exit 0
+
+

+This happens to be nearly identical in source to the implementation used by NetBSD. +

+

+Here's false(1) in Python rather than true(1) to demonstrate how exiting with an arbitrary exit status can be done: +

+

+import sys
+sys.exit(1)
+
+

+In some shells, true(1) is a shell built-in command, so running true will run the shell author's implementation of true(1) rather than the system implementation. +

+

+GNU true(1), from the GNU coreutils, deserves a special mention, as it's eighty lines long and directly includes four C header files. +This is not a joke. +Their true.c is 2.3 kilobytes, parses the arguments --help and --version (only if either are the first argument to the program), and I don't know how big the executable ends up being because the first thing I do when I take control of a GNU system is printf "#/bin/sh\nexit 0\n"|dd of="$(which true)";chmod +x "$(which true)" (use at your own risk). +

Cited media and further reading

+ +