[clug] Two (perhaps simple) shell questions.

David Deaves David.Deaves at dd.id.au
Wed Aug 19 07:35:14 MDT 2009


> On Tue, Aug 18, 2009 at 11:39, Mark Triggs<mark at dishevelled.net> wrote:
> 
> >> for i in `ls *.mnc`;
> >> do
> >>    do8ofthisatonce <program> $i $i.out
> >> done
> >
> > xargs will do this for you.  Something like:
> >  ls *.mnc | xargs -I'{}' -P 8 program {} {}.out
> 
> Thanks Mark, I knew that one day I should learn xargs.. ;)  Still
> while this will work in most of the things I do xargs doesn't seem to
> allow multiple commands?  ie (for arguments sake):
> 
> for i in `ls *.mnc`;
>  do
>     var=`basename $i`
>     do8ofthisatonce <program> $var $i.out
>  done
> 
> If the answer is "can't be done" then so be it. :)  I guess in this
> case I could make a quick shell script and call that using xargs but
> that sort of spoils the fun.
> 

I would do that with:

ls *.mnc | sed 's/\.mnc$//' | xargs -I'{}' -P 8  program  {}.mnc {}.out


Dave !




More information about the linux mailing list