ls | wc VS wc `ls`

Go down

ls | wc VS wc `ls`

Post by mightyganesh on Wed Mar 03, 2010 4:03 pm

Code:

[336474@oracleclient ~]$ ls
f7  tester
[336474@oracleclient ~]$ ls | wc
      2      2      10
[336474@oracleclient ~]$ wc `ls`
      1      1      17 f7
wc: tester: Is a directory
      0      0      0 tester
      1      1      17 total
[336474@oracleclient ~]$

note here that both ls | wc and wc `ls` does the same job of giving the output of ls command as input to wc command..
but we get two different outputs. can any one suggest the possible reason for this action??? Question
avatar
mightyganesh

Posts : 53
Points : 92
Join date : 2010-02-26
Age : 30

View user profile http://ganeshguna.blogspot.com

Back to top Go down

Re: ls | wc VS wc `ls`

Post by Christopher on Wed Mar 03, 2010 4:17 pm

"ls | wc" and "wc `ls`" are not equal.

In "ls | wc", wc receives only one argument which is the output of ls command. In the second command each line of ls command will be passed as argument to wc command.

In ur example, "wc `ls`" is similar to "wc f7 tester"
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum