[ale] command fails thru xargs but succeeds from shell prompt

Michael Potter michael at potter.name
Sat Jan 29 20:50:46 EST 2011


On Sat, Jan 29, 2011 at 8:31 PM, Brian Pitts <brian at polibyte.com> wrote:
> On 01/29/2011 03:43 PM, Mark Heiges wrote:
>> or use find's --print0 with xarg's -0 options.
>>
>>   find Video/* -maxdepth 0 -type d -print0  | xargs -0 -tn1 -I"{}" mv -
>> v {} /alt/video/
>
> Or use find's exec option rather than xargs.
>
> This would run one mv command for each directory, like what you're doing
> with -n1.
>
> find Video/* -maxdepth 0 -type d -exec mv '{}' /alt/video ';'
>
> This would run one mv command for all the directories, like xargs
> behaves by default.
>
> find Video/* -maxdepth 0 -type d -exec mv '{}' /alt/video '+'
>
> --
> All the best,
> Brian Pitts
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>

TIMTOWTDI:

find Video/* -maxdepth 0 -type d -print |while read fname
do
 mv -- "$fname" /alt/video '+'
done

1) spaces in the name should work because the last arg to read will
pick up all remaining arguments regardless of space.
2) this will work on systems that do not implement print0/-0
3) the -- in mv will tolerate fname beginning with -.
4) the "'s around $fname will allow fname to contain spaces.
5) doing it in a loop allows you to do multiple commands in the loop.
6) be aware that on bash that any variable you set in the while loop
will not be set outside of the while loop.

-- 
Michael Potter
Replatform Technologies, LLC
+1 770 815 6142
michael at potter.name



More information about the Ale mailing list