0
\$\begingroup\$

The well known cat command simply copies its stdin directly to stdout unchanged. But there are plenty of other commandline tools that exist...

What other commands can be used to duplicate the functionality of the venerable cat?

Rules

  1. You are not allowed to use any shell features, including pipes, file redirection, variables, etc.
  2. Your answer can only directly invoke one command - e.g. foo-cmd; bar is disallowed because you are directly invoking both foo-cmd and bar (not to mention, the use of a semicolon breaks rule 1). However, commands that internally execute other commands (such as xargs) are allowed.
  3. The command you use should already exist and be at least somewhat widely known. And an explanation of nontrivial answers would also be nice.
  4. This contest is not about finding a single "best" cat implementation, and as such will not have a single accepted answer. Rather, this is an exercise in creativity: how many different ways can we collectively implement cat?

Solutions

So far, we have a cat implementation for the following commands (add yours to the list when you answer):

\$\endgroup\$
3
  • \$\begingroup\$ @Seggan Not OP, but for me, no: (a) this is a popularity contest, and (b) this is assumingly only for bash. I'll request adding a bash tag. \$\endgroup\$
    – Joao-3
    Commented Jan 30 at 17:03
  • \$\begingroup\$ @Joao-3 but all these answers are just as valid answers for the other question. also popularity contests are very much frowned upon \$\endgroup\$
    – Seggan
    Commented Jan 30 at 17:08
  • \$\begingroup\$ @Seggan Different people have different opinions \$\endgroup\$
    – Joao-3
    Commented Jan 30 at 18:12

2 Answers 2

1
\$\begingroup\$

sed

sed ""

Plain old sed with an empty string.

\$\endgroup\$
0
\$\begingroup\$

awk

awk '1{print}'

Explanation:

  • 1 -> match every line.
  • {print} -> for each matched line, print it

Or, more tersely:

awk 1

Here, a missing block implies {print}.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.