Bash Scripting Help Needed

Kurt Wall kwall
Wed Oct 20 08:33:48 PDT 2004


On Tue, Oct 19, 2004 at 08:25:30AM +1000, James McDonald took 67 lines to write:
> OK I managed to get the result I wanted with this
> 
> find Admin/ -regex .*vbs$ -print0 -exec cp \{\} /home/jamesm/tmp/ \;

This is a fine example of a find command.

> BUT how the heck do you get xargs to pass the argument to the command in 
> the correct order?
> 
> I wanted to use xargs to cp files
> 
> find Admin -regex .*vbs$ -print0 | xargs --null cp $1 /home/jamesm/tmp/
> 
> but xargs kept appending the filename argument to the end of the cp command 
> instead of where I wanted it which in the command above is $1... so $1 
> expanded to nothing and the filename xargs passed became the target and 
> grrrrr.

I believe you ran into a limitation of xargs. It can only handle a command
followed by initial arguments because xargs just appends the input from (in
this case) find to the command specified. Does that make sense?

> I read the man page for xargs but it appears that the behaviour is that it 
> tacks everything on to the end of the command you specify and not insert it 
> as I'm trying to do.

Precisely.

Kurt
-- 
Paul's Law:
	You can't fall off the floor.


More information about the Linux-users mailing list