When I do this:
$ /bin/echo 123 | /bin/echo
I get no o/p. Why is that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You ask why it doesn’t work. In fact, it does work; it does exactly what you told it to do. Apparently that’s not what you expected. I think you expected it to print
123, but you didn’t actually say so.(Note: “stdin” is standard input; “stdout” is standard output.)
/bin/echo 123 | /bin/echoHere’s what happens. The
echocommand is executed with the argument123. It writes “123”, followed by a newline, to its stdout.stdout is redirected, via the pipe (
|) to the stdin of the secondechocommand. Since the echo command ignores its stdin, the output of the first echo is quietly discarded. Since you didn’t give the second echo command any arguments, it doesn’t print anything. (Actually, /bin/echo with no arguments typically prints a single blank line; did you see that?)Normally pipes (
|) are used with filters, programs that read from stdin and write to stdout.catis probably the simplest filter; it just reads its input and writes it, unchanged, to its output (which means thatsome-command | catcan be written as justsome-command).An example of a non-trivial filter is
rev, which copies stdin to stdout while reversing the characters in each line.prints
revis a filter;echois not.echodoes print to stdout, so it makes sense to have it on the left side of a pipe, but it doesn’t read from stdin, so it doesn’t make sense to use it on the right side of a pipe.