more markup
This commit is contained in:
parent
496fb0927e
commit
e8ad2bf89e
@ -69,14 +69,14 @@ window.load_highlighting = function(language){
|
||||
</P>
|
||||
<P>
|
||||
<CODE>cat</CODE> was introduced in UNIX v1 to supercede the program pr which printed the contents of a single file to the screen (McIlroy); its first-edition manual page described cat as “about the easiest way to print a file” (“cat(1)”).
|
||||
<CODE>cat</CODE>’s modern, typical use is more or less the same; it’s often introduced to UNIX beginners as a method to print the contents of a file to the screen, which is why many implementations of <CODE>cat</CODE> include options that are technically redundant - see the often-included <CODE>cat</CODE> -e, -t, and -v that replace the ends of lines, tabs, and invisible characters respectively with printing portrayals (“cat(1p)”).
|
||||
<CODE>cat</CODE>’s modern, typical use is more or less the same; it’s often introduced to UNIX beginners as a method to print the contents of a file to the screen, which is why many implementations of <CODE>cat</CODE> include options that are technically redundant - see the often-included <CODE>cat</CODE> <CODE>-e</CODE>, <CODE>-t</CODE>, and <CODE>-v</CODE> that replace the ends of lines, tabs, and invisible characters respectively with printing portrayals (“cat(1p)”).
|
||||
</P>
|
||||
<P>
|
||||
The POSIX standard as of 2003 requires only the option <CODE>-u</CODE> to be implemented, which prevents <CODE>cat</CODE> from buffering its output - on some systems, <CODE>cat</CODE> buffers its output in 512-byte blocks (McIlroy), similarly to <CODE>dd</CODE>’s default as defined by POSIX (“dd(1p)”), though most currently popular <CODE>cat</CODE> implementations do this by default and ignore the <CODE>-u</CODE> flag altogether (busybox, GNU coreutils).
|
||||
POSIX doesn’t mandate buffering by default - specifically, <CODE>-u</CODE> <I>has</I> to guarantee that the output is unbuffered, but <CODE>cat</CODE> doesn't have to buffer it in the first place and can ignore <CODE>-u</CODE> in that case.
|
||||
</P>
|
||||
<P>
|
||||
This is a POSIX-compliant implementation of UNIX cat with no additional features nor buffered output in C:
|
||||
This is a POSIX-compliant implementation of UNIX <CODE>cat</CODE> with no additional features nor buffered output in C:
|
||||
</P>
|
||||
<INPUT ID="c_toggle" ONCLICK="window.load_highlighting('c');" TYPE="button" VALUE="Press this button to enable syntax highlighting within this code." />
|
||||
<PRE><CODE CLASS="language-c">
|
||||
@ -172,7 +172,7 @@ main(int argc, char *argv[]){
|
||||
}
|
||||
</CODE></PRE>
|
||||
|
||||
<P>It’s worth noting that this concept of cat as a utility that sequentially prints given files to standard output means cat can be replaced by a simple shell script that does the same using dd and printf; cat as defined by POSIX is actually totally redundant to other POSIX utilities. Here’s the shell script:</P>
|
||||
<P>It’s worth noting that this concept of cat as a utility that sequentially prints given files to standard output means <CODE>cat</CODE> can be replaced by a simple shell script that does the same using <CODE>dd</CODE> and <CODE>printf</CODE>; <CODE>cat</CODE> as defined by POSIX is actually totally redundant to other POSIX utilities. Here’s the shell script:</P>
|
||||
<INPUT ID="shell_toggle" ONCLICK="window.load_highlighting('shell');" TYPE="button" VALUE="Press this button to enable syntax highlighting within this code." />
|
||||
<PRE><CODE CLASS="language-shell">
|
||||
#!/bin/sh
|
||||
@ -243,7 +243,7 @@ done
|
||||
exit 0
|
||||
</CODE></PRE>
|
||||
|
||||
<P>cat still has a purpose though. This shell script is relatively slow for short files and very slow for very large files (though dd itself should probably be used to copy large files from one medium to another anyway). This is provided for educational purposes (though I personally use this shell script in my system PATH; the C implementation provided compiles to a much larger binary using gcc 11.1.0, so this saves a couple kilobytes).</P>
|
||||
<P><CODE>cat</CODE> still has a purpose though. This shell script is relatively slow for short files and very slow for very large files (though dd itself should probably be used to copy large files from one medium to another anyway). This is provided for educational purposes (though I personally use this shell script in my system PATH; the C implementation provided compiles to a much larger binary using gcc 11.1.0, so this saves a couple kilobytes).</P>
|
||||
|
||||
<H2>Cited media and further reading</H2><UL>
|
||||
<LI>Articles<UL>
|
||||
|
Loading…
Reference in New Issue
Block a user