piping output to echo

Hi,

I was wondering why ls * | echo does not print the contents of the directory to the screen? The way I see it, ls * returns a whole lot of information, and then we pipe all this info to echo, so surely it should all come to our screen!

Is there a serious flaw in my understanding?

Thanks.

A

echo
The echo command echoes its arguments. Here are some examples:

% echo this
     this
   % echo $EDITOR
     /usr/local/bin/emacs
   % echo $PRINTER
     b129lab1

Things like PRINTER are so-called environment variables. This one stores the name of the default printer --- the one that print jobs will go to unless you take some action to change things. The dollar sign before an environment variable is needed to get the value in the variable. Try the following to verify this:

% echo PRINTER
PRINTER

----------------------------

you can use " ls " command in the following way

ls * | pg  #or
ls * | more 

There is a flaw in your assumptions, not your understanding. Your understanding is right in that if a command reads from stdin, then it should be able to process the input that it gets. But 'echo' does not read from stdin. It simply processes its argument list and prints whatever it gets to stdout.

When you do 'ls * | echo', the number of arguments passed to 'echo' are 0. This causes the following part of echo's code to kick in:

     55 	if (--argc == 0) {
     56 		(void) putchar('\n');
     57 		if (fflush(stdout) != 0)
     58 			return (1);
     59 		return (0);
     60 	}

I picked this up from the source code of 'echo' from the Solaris source.

To get the output that you want, you should execute something like this:

echo `ls *`

or

echo $(ls *)

Thanks a lot for your help, guys.

That makes sense. I appreciate it.

A