Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

ls | wc VS wc `ls`

2 posters

Go down

ls | wc VS wc `ls` Empty ls | wc VS wc `ls`

Post by mightyganesh 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
mightyganesh
mightyganesh

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

http://ganeshguna.blogspot.com

Back to top Go down

ls | wc VS wc `ls` Empty Re: ls | wc VS wc `ls`

Post by Christopher 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"
Christopher
Christopher
Admin

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

https://unixcpp.forumotion.com

Back to top Go down

Back to top


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