posix true
This commit is contained in:
parent
31f240b580
commit
e5cf62736c
@ -13,7 +13,7 @@
|
||||
<STYLE></STYLE>
|
||||
<TITLE>trinity dot moe</TITLE> <!-- Also considered: 1945-07-16T05:26-06:00 -->
|
||||
</HEAD>
|
||||
<!-- 2021-08-05 stock crash? :) -->
|
||||
<!-- 2021-08-05 stock crash? :) nope lol. worth a try -->
|
||||
<BODY>
|
||||
|
||||
<SCRIPT TYPE="application/javascript" SRC="/js/cookies.js" ></SCRIPT>
|
||||
@ -72,6 +72,7 @@ I'm vaccinated against COVID-19. Are you?
|
||||
<A HREF="/thegame">/thegame</A>;
|
||||
<B>knowledge</B>:
|
||||
<A HREF="/knowledge/netbsd/">NetBSD</A>;
|
||||
<A HREF="/knowledge/true">true(1)</A>;
|
||||
<B>shilling</B>:
|
||||
<A HREF="#stickers">#stickers</A>
|
||||
</I></P>
|
||||
|
72
homepage/knowledge/true.html
Normal file
72
homepage/knowledge/true.html
Normal file
@ -0,0 +1,72 @@
|
||||
<!DOCTYPE html>
|
||||
<HTML LANG="en">
|
||||
<HEAD>
|
||||
<LINK HREF="http://www.trinity.moe/knowledge/true" REL="canonical" />
|
||||
<LINK HREF="https://raw.githubusercontent.com/devenblake/homepage/main/favicon.ico" REL="shortcut icon" TYPE="image/x-icon" />
|
||||
<LINK HREF="/css/blank.css" ID="styling" REL="stylesheet" />
|
||||
<META CHARSET="UTF-8" />
|
||||
<META CONTENT="interest-cohort=()" HTTP-EQUIV="Permissions-Policy" /> <!-- FUCK GOOGLE -->
|
||||
<META NAME="viewport" CONTENT="width=device-width, initial-scale=1" />
|
||||
<TITLE>true(1)</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<P><A HREF="/">~ Return to the rest of the site</A></P>
|
||||
<SCRIPT SRC="/js/cookies.js" TYPE="application/javascript"></SCRIPT>
|
||||
<SCRIPT SRC="/js/sheets.js" TYPE="application/javascript"></SCRIPT>
|
||||
<SCRIPT TYPE="application/javascript">window.onload = window.initializesheets;</SCRIPT>
|
||||
<H1>POSIX true(1)</H1>
|
||||
<H3>updated 2021-08-06</H3>
|
||||
<HR ALIGN="left" SIZE="1" WIDTH="25%" />
|
||||
<P>
|
||||
<CODE>true(1)</CODE> is a tool that <I>only</I> quits silently with an exit status of 0.
|
||||
Similarly, <CODE>false(1)</CODE> is a tool that <I>only</I> 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 <CODE>true(1)</CODE>.
|
||||
These utilities find use in shell scripting, which, though extremely relevant to these utilities, is beyond the scope of this article.
|
||||
</P>
|
||||
<P>
|
||||
Because <CODE>true(1)</CODE>'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:
|
||||
</P>
|
||||
<PRE><CODE CLASS="language-c" DATA-LANG="c">
|
||||
int main(void) { return 0; }
|
||||
</CODE></PRE>
|
||||
<P>
|
||||
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 <CODE>true(1)</CODE> implementation in 0 bytes.
|
||||
However (<B>TODO</B>) it's to me unknown whether this is implementation-specific or POSIX-specified.
|
||||
The <I>usual</I> implementation in POSIX shell is also a one-liner if you ignore the shebang:
|
||||
</P>
|
||||
<PRE><CODE CLASS="language-shell" DATA-LANG="shell">
|
||||
#!/bin/sh
|
||||
exit 0
|
||||
</CODE></PRE>
|
||||
<P>
|
||||
This happens to be nearly identical in source to the implementation used by NetBSD.
|
||||
</P>
|
||||
<P>
|
||||
Here's <CODE><I>false</I>(1)</CODE> in Python rather than <CODE>true(1)</CODE> to demonstrate how exiting with an arbitrary exit status can be done:
|
||||
</P>
|
||||
<PRE><CODE CLASS="language-python" DATA-LANG="python">
|
||||
import sys
|
||||
sys.exit(1)
|
||||
</CODE></PRE>
|
||||
<P>
|
||||
In some shells, <CODE>true(1)</CODE> is a shell built-in command, so running <CODE>true</CODE> will run the shell author's implementation of <CODE>true(1)</CODE> rather than the system implementation.
|
||||
</P>
|
||||
<P>
|
||||
GNU <CODE>true(1)</CODE>, 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 <CODE>true.c</CODE> is 2.3 kilobytes, parses the arguments <CODE>--help</CODE> and <CODE>--version</CODE> (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 <CODE>printf "#/bin/sh\nexit 0\n"|dd of="$(which true)";chmod +x "$(which true)"</CODE> (<B>use at your own risk</B>).
|
||||
<H2>Cited media and further reading</H2><UL>
|
||||
<LI>Articles<UL>
|
||||
<LI><A HREF="https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html">Brian Raiter - A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux</A></LI>
|
||||
</UL></LI>
|
||||
<LI>Manual pages<UL>
|
||||
<LI><A HREF="https://www.unix.com/man-page/posix/1p/true/">true(1p)</A> (The Open Group, 2003)</LI>
|
||||
</UL></LI>
|
||||
<LI>Notable true implementations<UL>
|
||||
<LI><B>ongoing</B> started 1992 - <A HREF="https://www.gnu.org/">GNU</A>/<A HREF="https://www.gnu.org/software/coreutils/">coreutils</A> - <A HREF="https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true.c">src/true.c</A></LI>
|
||||
<LI><B>ongoing</B> forked from 4.4BSD-Lite2 - <A HREF="https://www.netbsd.org/">NetBSD</A>/<A HREF="https://github.com/NetBSD/src">src</A> - <A HREF="https://github.com/NetBSD/src/blob/trunk/usr.bin/true/true.sh">usr.bin/true/true.sh</A></LI>
|
||||
</UL></LI>
|
||||
</UL>
|
||||
</BODY>
|
||||
</HTML>
|
Loading…
Reference in New Issue
Block a user