You are not logged in.

#1 2007-04-16 05:12:24

mcover
Member
From: Germany
Registered: 2007-01-25
Posts: 134

[solved] findutils xargs not working as expected!!

As the topic states, I have the feeling that something is wrong with xargs.

$> echo "cmd1 cmd2 cmd3" | xargs echo
cmd1 cmd2 cmd3

is what i get.

it should be

cmd1
cmd2
cmd3

but it isn't.


anyone getting the same thing or is it just me?

or do i not understand xargs?

Last edited by mcover (2007-04-16 11:54:43)

Offline

#2 2007-04-16 07:49:59

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: [solved] findutils xargs not working as expected!!

Because that's how xargs works...
try

for i in $( seq 1 3 ) ; do 
  echo cmd$i
done

xargs just takes any words you feed into and make an as long as possible cmdline for the program you specify
So what you were trying would do this

"cmd1 cmd2 cmd3" would be given as parameters to the echo command which would look like this:
echo cmd1 cmd2 cmd3

If you realy want to use xargs for what your trying to do, you tell it to use max 1 parameter for the command... Try "man xargs"


Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

#3 2007-04-16 11:53:48

mcover
Member
From: Germany
Registered: 2007-01-25
Posts: 134

Re: [solved] findutils xargs not working as expected!!

ahh thanks (/me probably went too fast through that man-page).

well i thought it was wrong cuz on some shell-scripting tutorial site it said (or it made me believe xargs works the way i used to think it works). my bad roll

xargs -n 1

does exactly what i want.

Offline

Board footer

Powered by FluxBB