The cat program is a program that copies its standard input to its standard output. It is named after the Unix command cat, although this command is actually more powerful. The cat program is a popular problem.
Hello world and quine program
#!/usr/bin/cat Hello, world!
chmod +x the program file to make it executable:
$ chmod +x file
To execute it:
(assuming file is the filename of the program)
Other shell commands could be used in similar way, so there is reverse variant of cat language too. Unix command line utilities in this space include both
rev (reversing characters within each line) and
tac (reversing the order of lines in the input; cat backwards).
$ echo '!dlrow ,olleH' | rev Hello, world!
$ (echo 'world!'; echo 'Hello,') | tac Hello, world!
$ (echo '!dlrow'; echo ',olleH') | tac | rev # or ... | rev | tac Hello, world!
A simple "reverse cat" program could simply output the bytes of the input backwards, which for a conventional newline-delimited text file has roughly the effect of
tac combined (except for the treatment of the file's trailing newline).
While a regular cat program requires only O(1) storage space, a reverse cat program requires O(n) storage space, so as a popular problem it is a slightly more ambitious achievement.