Bash Scripting Help Needed
James McDonald
james
Mon Oct 18 16:54:29 PDT 2004
Kurt Wall wrote:
>On Mon, Oct 18, 2004 at 09:18:18PM +1000, James McDonald took 65 lines to write:
>
>
>>I have a directory on my Linux box named ~/Admin It contains 2 years of
>>scripts and hacks that I used to manage the windows (sorry for swearing)
>>boxes at my work.
>>
>>I am trying to grab all the vbs files under the ~/Admin tree and copy
>>them to a location so that I can sort and categorize them.
>>
>>This piece of code gets me a list
>>
>>find Admin/ -regex .*vbs$
>>
>>
>
>Try:
>
>find Admin/ -regex .*vbs -print0
>
>See the man page for why you should use -print0
>
>
>
>>now when I do some thing like
>>
>>for i in `find Admin/ -regex .*vbs$` ; do echo $i ; done
>>
>>
>
>`find Admin -regex .*vbs$` | xargs -null echo
>
>Combining find with -print0 and xargs with -null should handle your spaces
>problem.
>
>Kurt
>
>
OK I managed to get the result I wanted with this
find Admin/ -regex .*vbs$ -print0 -exec cp \{\} /home/jamesm/tmp/ \;
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 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.
More information about the Linux-users
mailing list