# Simple cat program

One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after the Unix shell utility cat it is of course much less powerful than the real thing, which is normally used to print (and concatenate) several files read from disc.

You should write a full program which reads the contents of the standard input stream and writes them verbatim to the standard output stream. If and only if your language does not support standard input and/or output streams (as understood in most languages), you may instead take these terms to mean their closest equivalent in your language (e.g. JavaScript's prompt and alert). These are the only admissible forms of I/O, as any other interface would largely change the nature of the task and make answers much less comparable.

The output should contain exactly the input and nothing else. The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation. This also applies to trailing newlines. If the input does not contain a trailing newline, the output shouldn't include one either! (The only exception being if your language absolutely always prints a trailing newline after execution.)

Output to the standard error stream is ignored, so long as the standard output stream contains the expected output. In particular, this means your program can terminate with an error upon hitting the end of the stream (EOF), provided that doesn't pollute the standard output stream. If you do this, I encourage you to add an error-free version to your answer as well (for reference).

As this is intended as a challenge within each language and not between languages, there are a few language specific rules:

• If it is at all possible in your language to distinguish null bytes in the standard input stream from the EOF, your program must support null bytes like any other bytes (that is, they have to be written to the standard output stream as well).
• If it is at all possible in your language to support an arbitrary infinite input stream (i.e. if you can start printing bytes to the output before you hit EOF in the input), your program has to work correctly in this case. As an example yes | tr -d \\n | ./my_cat should print an infinite stream of ys. It is up to you how often you print and flush the standard output stream, but it must be guaranteed to happen after a finite amount of time, regardless of the stream (this means, in particular, that you cannot wait for a specific character like a linefeed before printing).

• This is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

• Submissions in most languages will be scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8.

Some languages, like Folders, are a bit tricky to score. If in doubt, please ask on Meta.

• Feel free to use a language (or language version) even if it's newer than this challenge. Languages specifically written to submit a 0-byte answer to this challenge are fair game but not particularly interesting.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

Also note that languages do have to fulfil our usual criteria for programming languages.

• If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Headsecks or Unary), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

• Unless they have been overruled earlier, all standard rules apply, including the http://meta.codegolf.stackexchange.com/q/1061.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the author actually had to put effort into golfing the code.

### Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

## Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes


<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 62230; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 8478; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "//api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "//api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(42), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

• Bash, 3 bytes: cat – TheDoctor Oct 31 '15 at 19:02
• @TheDoctor I guess this would fall into the "don't use a builtin which does exactly what is needed" rule. – Paŭlo Ebermann Oct 31 '15 at 19:46
• @PaŭloEbermann There is no such rule, and the corresponding standard loophole is no longer accepted. (In fact, there is already a sh answer using cat which also contains a shorter solution using dd.) – Martin Ender Oct 31 '15 at 20:25
• If only it used standard methods of input and output: ///, 0 bytes. – Comrade SparklePony Mar 31 '17 at 19:33
• @SparklePony Except, you'd have to escape slashes and backslashes. – Martin Ender Mar 31 '17 at 20:35

# Emotinomicon, 5 chars / 15 bytes

⏫⏪⏬⏫⏩


Press "cancel" to exit the loop. Try it here!

⏫   ⏪   ⏬   ⏫   ⏩   explanation
⏫                   take one character as input, push it to the stack
⏪               open loop
⏬           pops and outputs top of stack as character
⏫       take one character as input, push it to the stack
⏩   close loop

• Would ⏪⏫⏬⏩ work? – Pavel Nov 18 '16 at 20:54
• @Pavel no it would not, since the stack would be falsey being empty and thus the loop would end. – Conor O'Brien Nov 18 '16 at 20:56

# NTFJ, 4 bytes

(*~^


An online interpreter can be found here.

NTFJ is an esoteric programming language, made by user @ConorO'Brien, intended to be a Turing tarpit. It is stack-based, and pushes bits to the stack, which can be later coalesced to an 8-bit number. The bytes of the input are pushed to the stack before the program is run, with the first byte on top. This particular program is fairly simple:

(      If top of stack is not 0:
*      Pop byte, output as a character.
~     Push 0.
^    Pop bit/byte and jump to the instruction at the corresponding index.
This moves us back to the beginning of the program, which is thus looped until the stack is empty.

• Try chopping off the last paren, it should still work. – Conor O'Brien Mar 2 '16 at 19:42
• @CᴏɴᴏʀO'Bʀɪᴇɴ Thanks, it does indeed! – ETHproductions Mar 15 '16 at 20:04
• +1 for the emote: *~^ – user48538 Mar 16 '16 at 8:08

# Gogh, 0 bytes



This is functional in a Gogh program with input.

### Usage

$./gogh <standard-flags> <code-or-path> <input>  In this case: $ ./gogh o "" <input>


# CoffeeScript/LiveScript/etc. (Node.js), 31 bytes

I'm not sure if any of those languages have been used yet, but here it is.

p=process;p.stdin.pipe p.stdout


Because it takes advantage of so few features, most of the CoffeeScript descendants with any notability would work with this code, including LiveScript, Coco, and IcedCoffeeScript.

Oh, and it does deal with infinite streams.

# 0815, 10 bytes

(interpreter, don't let the pirate icon scare you)

}: :!~$^:  Note that there is a trailing space at the end. This one survives trimmers: }:0:!~$^:0


They work the same.

Explanation

0815 has three memory registers: X, Y and Z. X is write-able, Z is read-able. Y cannot be directly accessed, but only with rotations. At start, X is 0x0, Y is 0x0 and Z is 0x0. 0815 only supports hexadecimal numbers. Labels point to a specific part in the code: the character after their definition. Here are the symbols used here:

• } :   :: } defines a label, : starts its parameter (the label),   is the label, and : closes the parameter, thus creating the label at this point (char 5).
• !: ! gets a byte from STDIN and stores it in X.
• ~ $: ~ is needed to rotate left, so that X is Y, Y is Z and Z is X. Then, $ is used to print the character in Z to the screen.
• ^ :  : ^ jumps to the label specified if Z is not 0x0. Note that closing is not required on this step, as this is the end of the program. This allows an un-copiable null byte to be printed.

## Seed, 7 Bytes

2 20093


Seed is a language which generates Befunge-93 with a length and a random seed. 2 is the length and 20093 is the random seed.

• And the byte count is...? – user48538 Jul 16 '16 at 6:46

# Gaot++, 113 bytes

bleeeet bleeeeeet bleeeeeeeeeeeet bleeeet b bleeeeeeeeeeeeet bleeeet b bleeeeeeet bleeeet bleeeeeeeeeet bleeeeeet


In Compressed Gaot++ it's 25 bytes:

4e6e12e4eb13e4eb7e4e10e6e


Cannot terminate on the offline interpreter, EOF is not recognized by the language :(

Online interpreter for both normal and compressed versions.

• Shall I create a verbal representation of this? – tuskiomi Nov 18 '16 at 21:17
• @tuskiomi What do you mean? Those are surely screaming gaots! – Erik the Outgolfer Nov 18 '16 at 21:47

# D, 6571 68 bytes

import std.c.stdio;void main(){for(int c;c=~getchar,c;)putchar(~c);}


The original version couldn't handle infinitely long lines, but we should still do better than the existing D solution's 94 bytes, so here's the D version of Dennis' C solution.

std.c.stdio is deprecated in favor of core.stdc.stdio, as is this use of the comma operator, but both are still legal as of the current version.

Edit 2: Saved 3 bytes thanks to Zachary's suggestions

• Um, I don't think you need the parens after getchar. – Zacharý Nov 26 '16 at 17:08
• You can save a byte by changing the int c;while(...) to for(int c;...;). – Zacharý Nov 26 '16 at 17:17
• @ZacharyT Good call on both counts. Down to 68 bytes. – Ray Nov 28 '16 at 21:43

# Casio FX-7000G, 3 bytes

Due to the low amount of storage, the calculator's programming mode used a tokenized language to save space. This makes it somewhat competitive for code-golf...

Program:

?→X


Explanation:

?       # Take input from user
→X     # Store in variable X
# Implicit: Print last value


Note that although this is 5 UTF-8 bytes, the calculator uses its own encoding to store this in 3.

# NewbieFuck, 4 bytes

[.,]


I guess this is non-competing I'm not aware of any working interpreter, but I found the spec online (esolangs.org).

If I understand correctly, this is the same as Brainfuck, but [ ... ] is actually do-while loop (always executes the first time).

So, although the Brainfuck answer needs to take input before entering the loop, ,[.,], this language can omit the first input and use [.,]

Note: as end of input is signified by 0 in brainfuck, this cannot handle null bytes. It will also prepend a null byte to the output.

• Why not do [,.] so that it doesn't prepend a null byte? – caird coinheringaahing Sep 3 '17 at 14:49
• Then it would append the Null EOF byte at the end, which just shifts the problem to the other end. – sundar - Remember Monica Jul 8 '18 at 17:44

Perl, 13 or 14 bytes, depending on whether -e counts

perl -pe'BEGIN{$/=\1}'  Although perl's -p switch normally reads a line at a time, and thus would require the input data either be finite, or have newlines in it, we can change the input record separator $/.

If $/ is reference to a number, it causes perl to read fixed length records. This has to happen inside a BEGIN block, or else at least one newline would be required in the input. # Lean Mean Bean Machine, 7 bytes O i ! ~  Marble spawns at O, i reads single character from STDIN to the marble's value, ! print's the marble's value as a Unicode character, ~ teleports the marble back up to the top. ## Evil, 4 bytes mrwb  This language can only handle 1 character of input at a time. m: Serves as a marking character for b. r: Reads a single character from stdin and stores it in the accumulator. w: Writes the value of the accumulator to stdout. b: Searches backwards for m and continues execution from there. (My) interpreter in C++ here: https://github.com/xprogram/esolot/tree/master/lang/evil Original interpreter in Java here: http://web.archive.org/web/20070906133127/http://www1.pacific.edu/~twrensch/evil/evil.java ## O, 7 bytes 1{io1}w  O is a new stack-based golfing language that aims to have as many 1-byte commands as possible. You can find O on GitHub. 1: pushes 1 for a truthy value. {: begin code block (like ruby) i: pushes input to stack o: outputs top of stack 1: as above }: ends code block w: repeatedly does code block immediately before it while top of stack is truthy (pops top of stack) • "aims to have as many 1-byte commands as possible"... so, it's Pyth or APL or CJam? – Sparr Nov 14 '15 at 8:35 • @Sparr More like GS2 or Seriously. – Martin Ender Nov 14 '15 at 8:42 # Excel VBA, 6+1 = 7 Bytes Since Excel VBA has no STDIN that handles input streams, the simplest way to address the prompt is to take input from a range on the ActiveSheet object (STDIN) and pass it onto the VBE immediate window (STDOUT) ?[A1];  Where [A1].Text has had ' preppended to its value (+1 Byte) ### Alternative Version, 64 Bytes To avoid the need for prepending the input with ', the user may instead check for an error or formula in [A1] and if so then return [A1].Formula else [A1] to the STDOUT in the VBE immediate window. [B1]="=IsFormula(A1)":?IIf([IsErr(A1)]Or[B1],[A1].Formula,[A1]);  • Do you need to test if it is a formula first? It seems to work for plain text with '[A1].Formula' – seadoggie01 Sep 7 '18 at 16:02 # Samau, 0 bytes An empty program in Samau is a cat program. It simply pushes the input onto the stack as a string, and prints the top of the stack. Since Samau is written in Haskell, it can handle infinite streams. # Malbolge, 9,502 bytes Only included here for the sake of completeness, not my code. Here is the author's page. ## Wumpus, 6 bytes i=) o%  Try it online! ### Explanation First, to understand the control flow, we'll need to look at the actual program grid. Wumpus uses a triangular grid, so characters are alternatingly placed in upward and downward triangles. Furthermore, as opposed to many other Fungeoids, Wumpus does not use a wrapping grid. Instead, the instruction pointer (IP) is reflected off the boundary of the grid. That leads to the following flow through the grid: Hence, Wumpus simply loops through the entire code (going right to left on the second line), i.e. i=)%o  A single loop iteration is simple enough: i Read one byte N from STDIN and push it to the stack. EOF gives -1. = Duplicate. ) Increment. Gives 0 at EOF. % Compute N % (N+1). At EOF this ends the program due to the division by zero. Otherwise, this just results in N itself. o Print the byte to STDOUT.  • How do you make these nice visualisations? – Jo King Feb 12 '18 at 4:59 • @JoKing I'm just scripting them up by hand in Mathematica. – Martin Ender Feb 12 '18 at 9:10 # Cascade, 7 6 bytes ?. ;,^  Basically works by going in a loop outputting an input character until EOF is reached I didn't realise the starting point wasn't required, -1 byte Try it online! # 1+, 13 bytes 1##,";1+1<1+#  Assuming EOF returns 0. If error-terminating is allowed, it becomes fairly trivial: # 1+, 7 bytes 1##,;1#  # Plumber, 16 bytes []=[[] [[[[= ][][  First answer in my new esolang! Programs in plumber are divided into 2 character wide units, each of which performs a certain function. All [] units on the top row will drop a packet containing the value 0. The one on the right will hit the [=, which will pop input and push it left into a right-facing branch dropper ([[). Branch droppers push in the direction they are facing, and also drop the value. When the value is pushed into the [=, it is outputted. Plumber uses -1 for EOF, and outputting a negative value does nothing. When the value drops into the ][][, it moves upward on the far left, passes through an increment ([) operator, and is picked up by the []. If it is not 0, is passes through the conditional (=[), and is dropped by the [] on the right. This continues until the input is -1. # I like frog, 11 bytes like i like  like i takes the input like prints all cells that were written to at any time by the program. # ARM Thumb-2 machine code (Linux, no libc), 18 bytes This version exits quite impolitely by crashing with Bad system call. However, the program itself doesn't print anything to stderr, the shell does. 😏 Machine code: 4669 2201 2703 1ef8 df00 4347 f087 0707 e7f9  Commented assembly:  .syntax unified .arch armv6t2 .thumb .globl _start .thumb_func // cat program (exits with SIGSYS) // read = syscall 3, write = syscall 4 _start: // use sp as a pointer for read/write mov r1, sp // one byte movs r2, #1 // start with read (3) movs r7, #3 .Lloop: // read (3) - 3 = 0 = stdin, write (4) - 3 = 1 = stdout subs r0, r7, #3 // syscall svc #0 // We multiply the syscall by r0. // On an error, r0 will be zero or negative, setting r7 to that muls r7, r0 // If r0 was 1, flip between read (3) and write (4) with xor. // Otherwise, any negative or zero value will set this to a // bad syscall, raising a SIGSYS. // Yes, ARM doesn't have syscall 7. eor.w r7, r7, #7 // loop indefinitely b .Lloop  If read and write return 1, the syscall will be multiplied by 1, doing nothing, and the eor.w will flip it between read (3) and write (4) by XORing 7. If read or write returns zero, the multiply will set r7 to 0 XOR 7, so it will try to run syscall 7, which, for some reason, doesn't exist on ARM. Therefore it crashes with a bad system call. If it returns negative, well, there obviously aren't any negative syscalls, and it also crashes with a bad system call. Otherwise, it is a fairly standard read/write loop, aside from using syscall arithmetic to swap between stdin and stdout. ## No errors, 22 bytes Machine code: 4669 2201 2703 1ef8 df00 2801 bf14 2701 f087 0707 e7f7  Commented assembly:  .syntax unified .arch armv6t2 .thumb .globl _start .thumb_func // cat program (clean exit) // AFAIK, there is nothing that is smaller than 22 bytes that // exits nicely. // exit = syscall 1, read = syscall 3, write = syscall 4 _start: // use sp as a pointer for read/write mov r1, sp // one byte movs r2, #1 // start with read (3) movs r7, #3 .Lloop: // read (3) - 3 = 0 = stdin, write (4) - 3 = 1 = stdout // exit doesn't really matter subs r0, r7, #3 // syscall svc #0 // On an error, r0 will not be 1. cmp r0, #1 ite ne // If we failed, set the syscall to exit (1). movne r7, #1 // Otherwise, flip between read (3) and write (4) with xor. eoreq.w r7, r7, #7 // loop indefinitely b .Lloop  This is roughly the same thing, only it wastes 4 bytes setting the syscall to exit when the syscall fails. I had an epic fail when writing this. I thought "oh, I can switch between read and write by XORing 1". And so I tried it, and it didn't work. I ran echo "test" | ./a.out aaaaaand my phone froze. 3 XOR 1 == 2. Syscall 2 is fork. I accidentally fork bombed my phone because I can't do math. 😂 # ARM Thumb-2 Linux ELF executable, 52 bytes We can actually pack the first version into an ELF executable quite nicely using the muppet labs method, for a full program at 52 bytes: xxd -g1 : 00000000: 7f 45 4c 46 01 00 00 00 00 00 00 00 00 00 01 22 .ELF..........." 00000010: 02 00 28 00 1b 00 01 22 1b 00 01 22 04 00 00 00 ..(...."...".... 00000020: 03 27 f8 1e 69 46 00 df 47 43 20 00 01 00 87 f0 .'..iF..GC ..... 00000030: 07 07 f6 e7 ....  Assembly with comments (le ugly hack intensifies): // Adaptation of // https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html // for an ARM cat program. //$ arm-none-eabi-as -march=armv6t2 -mthumb cat-arm.s -o cat-arm.o
// $arm-none-eabi-ld -Ttext 0x22010000 cat-arm.o -o cat-arm.elf //$ arm-none-eabi-objcopy -O binary cat-arm.elf cat-arm

.text              // A lie.
.arch   armv6t2    // Set architecture version
.thumb             // Needs to be Thumb to fit. ARM is too thicc.
.syntax unified
.org    0          // Start at offset 0
Elf32_Ehdr:
.byte   0x7F,'E','L','F'              // e_ident
Elf32_Phdr:
.word   1                                             // p_type
.word   0                                             // p_offset
// squeeze an instruction into the start offset
// 0x2201 -> movs r2, #1
.word   0x22010000 // same as -Ttext                  // p_vaddr
.short  2          // ET_EXEC        // e_type        // p_paddr
.short  40         // EM_ARM         // e_machine
.word   _start + 2                   // e_version     // p_filesz
.thumb_func
.globl _start
_start:
// start halfway into this word, it will be an instruction
// movs r2, #1     // len = 1
.word  _start + 2                    // e_entry       // p_memsz
// 0004 0000 -> just messing with r4 and r0, harmless
.word   4          // Elf32_Phdr     // e_phoff       // p_flags
movs    r7, #3     // write          // e_shoff       // p_align
.Lloop:
subs    r0, r7, #3 // fd (0 or 1)
mov     r1, sp     // buffer is sp   // e_flags
swi     #0         // do syscall
// We multiply the syscall by r0.
// On an error, r0 will be zero or negative.
muls    r7, r0                       // e_ehsize
// finish the ELF header. This is basically harmless.
// movs r0, r4
.short  0x20                        // e_phentsize
// movs r1, r0
.short  1                           // e_phnum
// If r0 was 1, flip between read (3) and write (4) with xor.
// Otherwise, any negative or zero value will set this to a
// bad syscall, raising a SIGSYS.
// Yes, ARM doesn't have syscall 7.
eor.w   r7, r7, #7
// loop indefinitely
b       .Lloop


One cool thing is that we don't need to branch over any header fields: 00xx is a simple movs, which we can deal with easily.

I actually start halfway into e_entry itself, using a custom p_vaddr which acts as an instruction, and ignoring the next two instructions.

I don't have a way to make an interactive demo yet until someone adds QEMU to TIO.

# ThumbGolf, 8 bytes

de10 de18 d0fc 4770


Assembly

        // Include ThumbGolf wrapper macros
.include "thumbgolf.inc"

// Who said you had to start at the top?
.Lloop:
// Print the byte in r0 to stdout
putc    r0 // udf #0020
// Fallthrough

.globl main
.thumb_func
// Entry point is here
main:
// Read a byte from stdin to r0.
// This sets the Z flag on success,
// allowing us to easily detect EOF.
getc    r0 // udf #0030
// If successful, go to the top to print
beq     .Lloop
// EOF or error, return
// this actually returns zero as a plus
bx      lr


ThumbGolf is a brand new, very WIP golfing extension to Thumb-2 I am making out of boredom.

It takes what I see as a RISC approach to a golfing language, giving you the tools to write the algorithm instead of giving you the algorithm itself.

I decided to make its initial debut with the classic cat program.

It doesn't have an online interpreter yet, but you can compile it yourself, and run it on ARM Linux (including Termux) or with qemu-arm.

# osascript, 14 bytes

on run a
a
end

Grabs all input from STDIN and returns it. This will not work for infinite input.

• This prints a trailing newline - I'm not sure how to get rid of it, but I'll try a few things. – Addison Crump Oct 30 '15 at 16:45

# AppleScript, 50 Bytes

(display dialog""default answer"")'s text returned

Opens a display dialog (equivalent to STDIN) and returns all the text input into the dialog pane out to the result pane. Will not support infinite input.

# Ruby, 22 bytes

putc$_ while$_=\$<.getc


Should handle null bytes and infinite streams.

# Curry, 16 bytes

main=interact id


Curry is a Haskell look-alike, so it shouldn't be surprising that a cat program looks... well, exactly the same in it :) It's lazy just like Haskell, so it handles infinite streams fine.

# Burlesque, 1 byte

Q


STDIN is pushed on the stack as a string. Q pretty-prints this string, which amounts to Burlesque not printing it "raw", i.e. surrounded by quotes. It's implicitly printed at the end of the program.

(I can't test it right now, but this might handle infinite streams? It's implemented in Haskell, so...)

• It handles infinite streams as well, yes. You can work on infinite streams i.e. try cat /dev/urandom | base64 | blsq --stdin "2coQ" and it will work just fine. However, not all built-ins are lazy. For example trying to do 2couN wont work because \[ is not lazy. Mapping however will work i.e. 2co)<-Q works fine. Also doing 2cop^ nor 2co^p will work. – mroman Nov 13 '15 at 17:25
• Additionally you need to know that some built-ins don't work natively on strings but Explode them and then Concat them back. That's why f[ won't work on infinite strings because f[ will do an auto-concat afterwards. So if you want to filter an infinite string you need to convert it to a block. For example XX:><2co)\[)rib2 works on infinite strings but if you don't do the XX it won't :). – mroman Nov 13 '15 at 17:30
• I think the reason is that \[ falls back to r[ and r[ produces a single value out of a block and thus can't possibly work on infinite lists. – mroman Nov 13 '15 at 17:32

# Frege, 16 bytes

main=interact id


Another Haskell-like, another totally equivalent cat program.