"cat"-like program

2

1

The mission is to implement a cat-like program (copy all STDIN to STDOUT).

Rules:

  • You may only use standard libraries
  • Indentation must be either two spaces or a single tab (in languages which require indentation)
  • Scripts must use shebangs
  • The result of cat anything.txt | ./yourprogram | diff anything.txt - should be nothing and should not be an infinite loop

Go example (84 bytes)

package main
import (
  "os"
  "io"
)
func main() {
  io.Copy(os.Stdout,os.Stdin)
} 

C++ example (78 bytes)

#include<iostream>
using namespace std;
int main() {
  cout << cin.rdbuf();
}

Ruby example (44 bytes)

#!/usr/bin/env ruby
$stdout << $stdin.read

Shortest code (by bytes) wins.

Kokizzu

Posted 2014-06-15T12:17:54.673

Reputation: 1 531

Question was closed 2015-10-30T16:36:56.307

1Sheesh why all the downvotes? – Conor O'Brien – 2015-10-28T04:58:04.280

Two space indentation isn't valid in Python. – seequ – 2014-06-15T12:34:34.067

55This indentation thing is nonsense – edc65 – 2014-06-15T12:49:01.183

1@edc65 Especially because it often isn't needed. – seequ – 2014-06-15T12:50:34.813

3@ProgramFOX Stoning the Rosetta. – seequ – 2014-06-15T12:53:48.960

2

@TheRare I'm not sure where you heard that, but any indentation is perfectly valid in Python. Different levels don't even need to have the same indentation. https://docs.python.org/3/reference/lexical_analysis.html#indentation

– Plutor – 2014-06-15T13:40:03.617

@Plutor Guess I've ran to some weird bugs then. – seequ – 2014-06-15T13:55:13.303

Even if there were a valid winning criterion, this seems a rather boring challenge. – Kyle Kanos – 2014-06-15T14:15:29.787

14The indentation rule doesn't make sense, the shebang one makes even less, because shebangs can be platform-specific, especially in the case of Python. – nyuszika7h – 2014-06-15T14:50:14.273

9until end of June 2914… Woaah… – Qeole – 2014-06-15T18:03:37.263

7Also, person with most implementation? What? – nyuszika7h – 2014-06-15T18:50:36.333

2what exactly prevents me from using cat in Bash, or all the 0 character programs in other languages? – None – 2014-06-15T19:40:27.237

1typo indeed XD 2014 – Kokizzu – 2014-06-15T22:47:19.887

1@TheRare With regards to Python indentation, it must be consistent within a block. So, each level must be self consistent, but it doesn't have to care about the other levels. If you aren't consistent within a block, then it will complain. – daviewales – 2014-06-18T09:11:22.480

1Why are there so many downvotes? – None – 2014-06-20T20:00:24.157

@professorfish: Because of the rules, I assume. Rule 2 is nonsense, rule 1 only makes sense for certain languages and counting the bytes of the shebang is a very weird form of scoring. So far, pretty much all answers seem to have ignored rule 3. – Dennis – 2014-06-20T20:05:38.697

@Dennis would it be legitimate to just edit it to make it clearer? – None – 2014-06-20T20:11:37.877

1@professorfish: The rules aren't unclear, they're just very, very strange. I don't think we should actually change the rules of a contest. – Dennis – 2014-06-20T20:14:54.290

to bee correct with the size in my opinion also the size of the used interpreter must be added otherwise it is useless to compare the code snippets. also it should be cleared what happens if the code must be compiled to us (e.g java, c) what counts the size of the source code or the size of the binary ? – konqui – 2014-06-25T20:59:36.963

4what about this python solution? for s in' /\___/\|( o o )|/ * \|\__\_/__/meow| / \| / ___ \| \/___\/'.split('|'):print s – Willem – 2014-07-04T15:50:09.677

1@professorfish, why are there so many upvotes? – Peter Taylor – 2014-08-05T16:43:43.893

this isn't even cat-like as much as it is echo-like. – Jordon Biondo – 2014-08-05T18:46:24.867

Using cat with only one argument to just print out the file is easily the most frequent use case, but people apparently forget that cat stands for "concatenate" - most solutions here don't do that. – orion – 2014-08-05T19:01:27.173

@orion: that's because OP ignored it too: "copy all stdin to stdout". Handling arguments is harder. – Yann Vernier – 2014-09-11T11:12:02.383

Answers

45

GolfScript, 0 characters / bytes

This could technically be considered invalid since GolfScript will append a \n, but that can be fixed with :n; (3 bytes).

Doorknob

Posted 2014-06-15T12:17:54.673

Reputation: 68 138

6Haha, +1. Explanation for people who don't speak golfscript: stdin is read to the stack when the program starts and the stack is outputted when it ends. – seequ – 2014-06-15T12:47:06.857

2Nice idea, but invalid. GolfScript will append a linefeed to the input. – Dennis – 2014-06-15T13:55:03.037

1@Dennis That could be fixed in 3 bytes: :n; (edited) – Doorknob – 2014-06-15T14:11:57.663

4I would say then that the zero-char solution is, unfortunately, invalid, and therefore the score is a solid 3. +1 nonetheless! – Jwosty – 2014-06-16T04:56:38.993

24

sed - 0 bytes

No command needed to cat a file with sed: all lines of input are printed without modification, so

sed ''

will act like cat for standard input, and

sed '' /etc/fstab

will print content of file.

Qeole

Posted 2014-06-15T12:17:54.673

Reputation: 641

"sed n" works for me and is one byte shorter. – Glenn Randers-Pehrson – 2014-08-05T18:04:24.107

@GlennRanders-Pehrson Yes, thank you. I didn't count the quotes as part of the sed script (I considered an empty script, something similar to sed -f /dev/null input). If we are to count chars on the line, your proposal saves a byte indeed. – Qeole – 2014-08-05T20:54:01.587

18

ΒrainFuck (5 bytes)

,[.,]

Explanation:

,  Read first byte of input and place on stack
[  While top byte is not 0...
 . Print top byte from stack as ASCII and remove
 , Read next byte of input and place on stack
]  ...loop

kitcar2000

Posted 2014-06-15T12:17:54.673

Reputation: 2 689

@Claudiu how else would you tell when the file ends? This is BF :P – clap – 2015-12-04T16:28:12.017

4one of those few tasks where BF is shorter than most other things... – None – 2014-06-20T19:54:27.997

This is less than 2 bytes (each command is 3 bits... totaling 15 bits). – Timtech – 2014-06-23T23:01:28.703

2It is not 3 bits when stored in ASCII format, and I wrote it as ASCII. – kitcar2000 – 2014-06-24T14:35:06.303

This will fail on files with a null in them though.. – Claudiu – 2014-09-10T20:46:42.757

15

Haskell - 17 bytes

main=interact id

id is the identity function and from the documentation :

The interact function takes a function of type String->String as its argument. The entire input from the standard input device is passed to this function as its argument, and the resulting string is output on the standard output device.

gxtaillon

Posted 2014-06-15T12:17:54.673

Reputation: 577

10

x86_64 NASM Assembly for Linux - 125 / 100

r:mov ax,0
mov di,0
mov rsi,c
mov dx,1
syscall
cmp ax,0
je e
mov di,1
syscall
jg r
e:mov ax,60
syscall
SECTION .bss
c:resw 1

I couldn't get it to fit in 100 bytes, but it is assembly. Eight bytes could be saved at the cost of changing the return status to 1 instead of 0:

r:mov ax,0
mov di,0
mov rsi,c
mov dx,1
syscall
cmp ax,0
mov di,1
jg s
mov ax,60
s:syscall
jg r
SECTION .bss
c:resw 1

Now, if you really want 100 bytes, here is one in exactly 100 bytes. The problem is that it doesn't exit correctly, it just segfaults:

r:mov ax,0
mov di,0
mov rsi,c
mov dx,1
syscall
cmp ax,0
mov di,1
syscall
jg r
SECTION .bss
c:resw 1

The instructions say to only use standard libraries; is there extra credit for using no libraries at all?

Ian D. Scott

Posted 2014-06-15T12:17:54.673

Reputation: 1 841

6

C 43

main(c){while((c=getchar())>=0)putchar(c);}

edc65

Posted 2014-06-15T12:17:54.673

Reputation: 31 086

3You can use ~(c=getchar()) instead of (c=getchar())>=0 to save 2 characters. – nyuszika7h – 2014-06-15T13:59:58.413

1@nyuszika7h: EOF is typically -1, but this is not guaranteed by the standard. The standard only defines about EOF in section 7.19.1:

EOF which expands to an integer constant expression, with type int and a negative value, that is returned by several functions to indicate end-of-file, that is, no more input from a stream;
 – edc65  – 2014-06-15T16:11:48.727

main(){for(;putchar(getchar())<127;);} what's with that? (apparently putchar's return value is casted to int so EOF becomes 255) – bebe – 2014-06-18T17:54:45.090

@bebe yes it's pity. putchar get an int but truncates it to 8 bits. (It's in the spec) – edc65 – 2014-06-18T18:35:57.550

@edc65 VC++ error C2065: 'c':undeclared identifier. Yes, sorry my comment about putchar was incorrect. – bacchusbeale – 2014-06-23T19:43:08.393

@bacchusbeale compile as C, not C++. 'c' is defined as the first argument of main function – edc65 – 2014-06-23T19:52:43.747

5

Linux/Unix tools, 16 bytes

#!/bin/sh
grep $

Other tools that work when called by bash/sh are

tr . .

and (15 bytes)

sed n

EDIT: Changed title from "bash/sh" to "Linux/Unix tools" because although the tools can be called by bash or sh they aren't actually part of bash or sh.

Glenn Randers-Pehrson

Posted 2014-06-15T12:17:54.673

Reputation: 1 877

1Copies the indentation? – seequ – 2014-06-15T12:54:34.777

@TheRare yes. It copies "all stdin to the stdout," as required. I guess that the 2-space indentation requirement refers to indentation of the code. – Glenn Randers-Pehrson – 2014-06-15T12:59:02.110

1Yes, yes it does. – seequ – 2014-06-15T13:01:17.343

shebangs don't count towards your score (and why are they #!/bin/sh? that isn't bash) – None – 2014-06-18T16:35:31.663

@professorish /bin/sh is Bash on my platform (Ubuntu 14.04) Perhaps I should have said Ubuntu and RedHat Fedora in my answer instead of "many systems" (will edit accordingly). In the example for ruby shown in the question, the shebang is counted among the 44 bytes. – Glenn Randers-Pehrson – 2014-06-18T16:47:43.950

@GlennRanders-Pehrson hmmm I have Ubuntu 14.04 and /bin/sh definitely goes to the Bourne shell... nevermind – None – 2014-06-20T20:01:35.223

No modern system uses a plain Bourne shell as /bin/sh. Today /bin/sh is usually the Almquist shell, bash, or ksh93. OpenBSD uses pdksh as /bin/sh. A modern /bin/sh has POSIX features like export PARAM=value and echo $((1 + 2)). The classic SVR4 Bourne shell has fewer features but should still be enough to run this answer. – kernigh – 2014-06-20T20:49:35.753

tr is part of the toolbox, tr is not bash – Emmanuel – 2014-08-05T15:31:24.947

@Emmanuel neither is grep; in fact tr is more in Bash than grep, because tr is in coreutils and grep isn't – None – 2014-08-05T16:07:09.190

5

Node.js 55

#!/usr/bin/env node
process.stdin.pipe(process.stdout);

Nikolai

Posted 2014-06-15T12:17:54.673

Reputation: 151

1Could shorten by assigning p=process first to avoid repetition. Just plain #!env node works unless you've got a non-standard filesystem layout or funky $PATH stuff going on. Alternatively, drop the shebang line (so the default sh is used) and do node -e '<program>' because that's the same (6) extra number of characters and stays system-general. (If you want to join the dark side, rename your node binary to n.) Aaand drop the semicolon. – Anko – 2014-09-15T09:41:38.243

5

Bash, 3

If you need a shebang, #!/bin/sh or #!/bin/bash is probably fine.

Had to be done. Hopelessly uncreative.

cat

Slightly more interesting:

tee

Normally, tee FILENAME sends its input both to the file and to standard output. Without an argument, it seems to behave like cat.

Bash, 2

...if you don't mind the status message at the end and the fact that the output only comes after EOF on standard input!

dd

Removing the status message costs 4 chars for a total of 6 chars:

dd 2>a

The message is sent to the file a instead of standard output.

If you dispose of the message entirely, the total length is 14 7:

dd 2>&-

Bash/SHELF, 1

For the shebang, try

#!/bin/sh
. shelf.sh

where shelf.sh is the location of your SHELF file.

SHELF is my PYG-like golfing library for Bash.

D

D just aliases to cat. Also uncreative.

And the alias for tee is...

5

user16402

Posted 2014-06-15T12:17:54.673

Reputation:

22>&- is shorter than 2>/dev/null. – nyuszika7h – 2014-06-26T11:35:30.523

5

Perl (1)

0+1 for the -p parameter

If really the shebang counts, invoke it like this: perl -p nul on M$ or perl -p /dev/null on *nix so no shebang is involved :P

D:\>copy con cat.pl
#!perl -p
^Z
        1 file(s) copied.

D:\>type cat.pl
#!perl -p

D:\>type cat.pl | cat.pl
#!perl -p

D:\>

core1024

Posted 2014-06-15T12:17:54.673

Reputation: 1 811

4

CJam - 1

q

No extra newline :)

aditsu quit because SE is EVIL

Posted 2014-06-15T12:17:54.673

Reputation: 22 326

3

AWK - ???

The complete program in awk has only 1 char:

1

Unluckily the shebang stuff lets kinda explode it's length :(

#!/usr/bin/awk -f
1

May I copy awk into the filesystem root? >;-)

As oneliner it is shorter:

$ awk 1 </etc/hostname 
darkstar

I'm not sure what counts and what not...

user19214

Posted 2014-06-15T12:17:54.673

Reputation:

5In my experience, code in codegolf doesn't use shebangs, it is intended to be directly executed by the interpreter (awk in this case). – Ramchandra Apte – 2014-06-15T13:42:57.213

Thinking about stdout = g(f(stdin))... <input tac|tac >output fails if the last input line has no linefeed. I like <input rev|rev >output. So far for f = g. What comes into the game for f != g? tr and it's inverse? sed and backwards? Smells not really promising... – None – 2014-06-17T14:59:58.673

A flash of enlightenment hit me: tee ftw!!! :) – None – 2014-06-18T14:35:58.383

At least in OpenBSD, printf 'full\0string' | awk 1 outputs 'full\n', so it is not perfect. I wonder if gawk or mawk does better? – kernigh – 2014-06-20T21:01:29.187

3

Ruby, 2 bytes (or 1?)

#!/usr/bin/env ruby -p

The question states that the shabang needs to be included. The 2 bytes counted is the -p part of the shebang. The otherwise empty script makes Ruby behave exactly likes cat when run with the p switch: Run it without arguments and it will take input from stdin, or with arguments and it print the contents of those files.

edit:

Ruby, 8 bytes

@core1024 had already posted a solution in Perl similar to the one above, so here is another attempt. Note that the following are not scripts, they are Ruby programs ;)

puts *$<

Ruby, 16 bytes

I think this one is cute

print while gets

daniero

Posted 2014-06-15T12:17:54.673

Reputation: 17 193

3

16 bit .com binary for MSDOS - 31 Bytes (112 Byte NASM Source)

00 00 BA 00 00 B9 01 00 B4 3F BB 00 00 CD 21 83 F8 00 74 09 B4 40 BB 01 00 CD 21 EB EB CD 20

The nasm source code:

c:resw 1
mov dx,c
mov cx,1
r:
mov ah,63
mov bx,0
int 33
cmp ax,0
je e
mov ah,64
mov bx,1
int 33
jmp r
e:
int 32

Build with "nasm -f bin -o cat.com cat-msdos.s".

I already provided a solution for x86_64 Linux, but was unable to get it under 100 bytes. This is over 100 bytes of assembly, but the actually binary is only 31 bytes! This must be the simplest solution here.

Ian D. Scott

Posted 2014-06-15T12:17:54.673

Reputation: 1 841

2

Python 2.x - 56 or 61 bytes

Input limited to 10^9 bytes.

#!/usr/bin/python
from os import*
write(1,read(0,10**9))

Or for infinite input (61 bytes):

#!/usr/bin/python
from sys import*
stdout.write(stdin.read())

Not much to say, is there?

seequ

Posted 2014-06-15T12:17:54.673

Reputation: 1 714

1This isn't cat because it adds a linefeed or whatever your system uses (cr+lf?) to the output. – None – 2014-06-15T13:29:13.367

@yeti You're right. I use Windows atm, so couldn't remember that. Fixing... – seequ – 2014-06-15T13:39:59.627

@yeti Better now? – seequ – 2014-06-15T13:56:15.703

You can use 1e9 instead of 10**9 to save 2 characters. Also, the shebang doesn't count towards character count. – nyuszika7h – 2014-06-15T14:02:23.117

@nyuszika7h 1e9 is float while os.read requires an int. Also, the question specifically says to include the shebang. – seequ – 2014-06-15T14:05:05.417

I see. You can use import sys;print sys.stdin.read(), (note the trailing comma) for the second example to save 11 characters. – nyuszika7h – 2014-06-15T14:51:51.827

1@nyuszika7h That prints an extra space. – seequ – 2014-06-15T15:05:57.047

I should check my suggestions before posting them. >_> It actually prints a newline for me. Python is weird. – nyuszika7h – 2014-06-15T15:18:46.560

@CeesTimmerman I know. This answer uses Python 2. – nyuszika7h – 2014-06-26T10:34:39.650

@CeesTimmerman I don't see a reason to use Python 3 yet. Python 2 is faster and often better for golfing. – seequ – 2014-06-26T11:11:58.473

@CeesTimmerman Ah, sorry then. – seequ – 2014-06-26T11:48:35.227

2

Common Lisp

ECL, 106

#!/usr/local/bin/ecl -shell
(ignore-errors(loop(write-byte(read-byte *standard-input*)*standard-output*)))

SBCL, 109

#!/usr/local/bin/sbcl --script
(ignore-errors(loop(write-byte(read-byte *standard-input*)*standard-output*)))

CLISP, 188 180

#!/usr/local/bin/clisp
(let((i(make-stream 0 :element-type'(mod 256)))(o(make-stream 1
:direction :output :element-type'(mod
256))))(ignore-errors(loop(write-byte(read-byte i)o))))

These are the shortest programs that I can make, yet none are under 100 bytes.

The main problem is that *standard-input* and *standard-output* are character streams, not byte streams. A simple (loop(write-char(read-char)) would copy the characters but would fail to preserve bytes that did not form valid characters. Now my Common Lisp implementations want to use UTF-8 (perhaps because my locale is UTF-8), but I want to copy binary files that my not be valid UTF-8. Therefore I must copy bytes, not characters.

In ECL and SBCL, standard input and output are bivalent for both bytes and characters. I may use read-byte and write-byte, but those functions lack default streams, so I must pass *standard-input* and *standard-output* as arguments.

CLISP insists that *standard-input* and *standard-output* transport only characters. The way around this is to call ext:make-stream on file descriptor 0 (standard input) and file descriptor 1 (standard output) to make binary streams.

All three programs loop byte by byte. This is a slow way to copy bytes. A faster way would use a vector of 16384 bytes with read-sequence and write-sequence, but the program would be longer.

kernigh

Posted 2014-06-15T12:17:54.673

Reputation: 2 615

2

Batch (8)

type CON

Type writes file content to the console and CON is treated as a file containing all console input.

kitcar2000

Posted 2014-06-15T12:17:54.673

Reputation: 2 689

I like how this has a one-to-one correspondence with Bash: type to cat, con to /dev/stdin – clap – 2015-12-04T16:33:00.827

2

TI-BASIC, 12

While 1:Input Str1:Disp Str1:End

Timtech

Posted 2014-06-15T12:17:54.673

Reputation: 12 038

Use "Str1" instead of "A". – Conor O'Brien – 2015-10-28T05:01:05.553

@CᴏɴᴏʀO'Bʀɪᴇɴ Thanks for the tip, I was really bad at TI-Basic a year ago. Only problem is you can't use the STO-> arrow but you couldn't before either. It seems so silly that I used A instead of a string var :P again, thanks for the tip! – Timtech – 2015-10-29T00:46:23.147

@ThomasKwa Good idea. – Timtech – 2015-10-29T21:39:44.713

2

Java 68 104

My first approach at this:

class a{public static void main(String[]a){System.out.print(a[0]);}}

EDIT: Yeah, I misunderstood the concept, here is another attempt, I couldn't get it done in less than 100 chars so I'd appreciate any suggestion:

class a{public static void main(String[]a)throws Exception{for(;;)System.out.write(System.in.read());}}

BrunoJ

Posted 2014-06-15T12:17:54.673

Reputation: 659

1That's not how cat works. cat displays the contents of the file(s) given as command line arguments, or takes input from stdin when there are no arguments. – daniero – 2014-06-24T23:16:35.300

1@daniero Yeah I wasn't right, it works now, although much longer. – BrunoJ – 2014-06-25T18:33:35.777

This breaks the rule about looping forever, how about: class a{public static void main(String[]a)throws Exception{int r;while(0<(r=System.in.read()))System.out.write(r);}} – Roy van Rijn – 2014-09-15T11:29:11.723

2

zsh, 15 bytes

#!/bin/zsh
1<&1

Note that there is no newline at the end of the file.

Juan I Carrano

Posted 2014-06-15T12:17:54.673

Reputation: 71

2

Some Perl:

#!/usr/bin/perl
print<>;

25 bytes with shebang. This can also be much smaller with die(), and by bending the rules ever so slightly:

die<>

Executing the 4th test could only be done like this:

cat bla|perl ./perlcat 2>&1|diff bla -

<> is an abbreviation for <STDIN>. The 25 byte print example is pretty self explanatory. die() is normally used for exiting non-zero and outputting an error message, hence using the 2>&1 to bend the rules around the 4th test.

It also appears that the semicolon is not required for the last statement in Perl, so the first example could be brought down to 24 bytes.

taomanjay

Posted 2014-06-15T12:17:54.673

Reputation: 21

2

Perl6, 14 bytes:

.say for lines

And, if it doesn't need to be deterministically printing it in the correct order (hehe), you can use the auto-threading "map-apply"

lines>>.say

Ven

Posted 2014-06-15T12:17:54.673

Reputation: 3 382

2

><>, 7 bytes

I know a ><> solution already exists, but I figured it would be welcome.

i:0(?;o

Click here to try it

DanTheMan

Posted 2014-06-15T12:17:54.673

Reputation: 3 140

1

GML, 37

while(1)show_message(keyboard_string)

Timtech

Posted 2014-06-15T12:17:54.673

Reputation: 12 038

1

Rust - 74

Really generic...

use std::io;fn main(){for l in io::stdin().lines(){io::print(l.unwrap())}}

No Comment - 12

'=|@^:'&|:'&

Unimplemented, so, yeah.

cjfaure

Posted 2014-06-15T12:17:54.673

Reputation: 4 213

1

Dart - 48

import"dart:io";main(){stdout.addStream(stdin);}

lrn

Posted 2014-06-15T12:17:54.673

Reputation: 521

1

Groovy - 45 bytes

#!/usr/bin/env groovy
System.out << System.in

And test:

$ cat FirstJsonObj.groovy | ./Cats.groovy | diff FirstJsonObj.groovy  -
$ 

Will Lp

Posted 2014-06-15T12:17:54.673

Reputation: 797

1

Tcl 57

#!/usr/bin/env expect
while {[gets stdin d]>=0} {puts $d}

wolfhammer

Posted 2014-06-15T12:17:54.673

Reputation: 1 219

1

Swift, 32

while let l=readLine(){print(l)}

Prints every line until EOF is reached

If you're really picky that this doesn't work with an empty line at the end or whatever you can use this:

while let l=readLine(stripNewline:false){print(l,terminator:"")}

Kametrixom

Posted 2014-06-15T12:17:54.673

Reputation: 426

1

MATLAB, 18 bytes

fprintf(input(''))

Cannot use disp as it appends a newline to the output.

Stewie Griffin

Posted 2014-06-15T12:17:54.673

Reputation: 43 471

1

Simplex v.0.7

bg
b  ~~ take string input
 g ~~ output strip

Simple enough.

Conor O'Brien

Posted 2014-06-15T12:17:54.673

Reputation: 36 228

I need an "output all" character now. c: – Addison Crump – 2015-10-27T17:03:54.097

1

TeaScript, 1 byte

x

Input is given in the first input field. Compile online here.

user41805

Posted 2014-06-15T12:17:54.673

Reputation: 16 320

0

Shell script, 11 bytes (including shebang)

#!/bin/cat

fluffy

Posted 2014-06-15T12:17:54.673

Reputation: 725

XD somehow my cat was on /usr/bin/cat XD – Kokizzu – 2014-06-26T10:15:57.330

This isn't technically a shell script, it's a cat script. The shell isn't involved for executables with a shebang, unless the shebang happens to point to the shell. – nyuszika7h – 2014-07-02T18:20:45.820

@nyuszika7h Arguably it's a shell script that's just using cat as the shell. – fluffy – 2014-07-03T05:06:53.107

But this is not a cat program. This is a quine. – jimmy23013 – 2014-07-04T08:18:20.977

@user23013 Oh, so it is. – fluffy – 2014-07-05T05:46:45.673

0

Hassium, 52 Bytes

use IO;func main(){println(File.readText(args[0]));}

Expanded:

use IO;

func main () {
    println(File.readText(args[0]));
}

Jacob Misirian

Posted 2014-06-15T12:17:54.673

Reputation: 737

-1

grep - 2 or 7 bytes

grep ''

Tested on Linux.

The "program" of '' is two bytes but the complete command is 7 bytes.

Ken A

Posted 2014-06-15T12:17:54.673

Reputation: 585

2Actually, '' as a grep program won't work (try printf "#!/bin/grep\n''" > prog; chmod +x prog; ./prog). In your example, '' is just shell quote syntax. I can't see a way to run this with grep as interpreter, so this should count as a 7-byte shell script. – nyuszika7h – 2014-07-02T18:14:43.480

'' as a program will work from the interactive shell:

"seq 100 | grep '' | md5sum" produces the same result as "seq 100 | md5sum" (ignore the double quotes) – Ken A – 2014-07-02T18:52:42.370

-2

Many languages (49)

print("\\    /\\\n )  ( \')\n(  /  )\n \\(__)|");

Because :3 is more like a tame lion.

Mardoxx

Posted 2014-06-15T12:17:54.673

Reputation: 35

1That's not what the question is asking for, although it sounds like it :) – aditsu quit because SE is EVIL – 2014-06-25T09:22:56.457

I couldn't resist! – Mardoxx – 2014-06-26T12:16:23.773

-2

Ruby, 21 characters

#!/usr/bin/env ruby
while 1;puts gets;end

190n

Posted 2014-06-15T12:17:54.673

Reputation: 101

1but it won't stop '___' – Kokizzu – 2014-07-01T02:15:52.500

testing command: cat anything.txt | ./cat.rb – Kokizzu – 2014-07-01T02:16:15.410

neither will cat – 190n – 2014-07-01T21:23:57.933

1@fogcityben For me cat stops looping when it reads EOF. What version of cat are you working from? – Anko – 2014-09-15T09:50:14.393