Oh, yeah.<br><br>[-P max-procs]<br><br><br><br><div class="gmail_quote">On Tue, Aug 28, 2012 at 10:40 AM, Matthew <span dir="ltr"><<a href="mailto:wonderzombie@gmail.com" target="_blank">wonderzombie@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Not to further discourage you from experimenting, but xargs can also<br>
run commands in parallel. Check out the -P argument. :)<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Aug 28, 2012 at 8:19 AM, Hong Yang <<a href="mailto:hyangfji@gmail.com">hyangfji@gmail.com</a>> wrote:<br>
> Hi Brent,<br>
><br>
> Thanks for the xargs command info. I did not know it before.<br>
><br>
> The other reason I want to play with my mapm version is eventually I want to<br>
> make it concurrent.<br>
><br>
> Thanks again,<br>
><br>
> Hong<br>
><br>
><br>
> On Tue, Aug 28, 2012 at 10:08 AM, Brent Yorgey <<a href="mailto:byorgey@seas.upenn.edu">byorgey@seas.upenn.edu</a>><br>
> wrote:<br>
>><br>
>> I do not know the solution to your problem -- dealing with shells,<br>
>> environments, etc. can be tricky.<br>
>><br>
>> However, do you know about the 'xargs' command? E.g. your example<br>
>> could be accomplished with<br>
>><br>
>> ls | xargs -L 1 -I{} cp -pr {} destination_dir/{}<br>
>><br>
>> -Brent<br>
>><br>
>> On Tue, Aug 28, 2012 at 09:58:16AM -0500, Hong Yang wrote:<br>
>> > Hi,<br>
>> ><br>
>> > I am trying to mimic mapM() at shell command line. I define the<br>
>> > interface<br>
>> > as "mapm cmd2 cmd1," so cmd2 will be run for each of the cmd1 results.<br>
>> > "$_"<br>
>> > can be used inside cmd2 to represent the current cmd1 result.<br>
>> ><br>
>> > For example, the command<br>
>> > mapm 'cp -pr $_ destination_dir/$_' ls<br>
>> > copies everything under the current directory to the destination<br>
>> > directory.<br>
>> ><br>
>> > The code is as follows:<br>
>> ><br>
>> > --<br>
>> > module Main where<br>
>> ><br>
>> > import System.Environment ( getArgs )<br>
>> > import System.Exit<br>
>> > import System.IO<br>
>> > import System.Process<br>
>> > import Text.Regex<br>
>> > import Text.Regex.Posix<br>
>> ><br>
>> > main = do<br>
>> > hs_argv <- getArgs<br>
>> > if length hs_argv /= 2<br>
>> > then<br>
>> > putStrLn "wrong arguments!" >> exitFailure<br>
>> > else do<br>
>> > let [cmd2, cmd1] = hs_argv<br>
>> > (_, hOut, hErr, _) <- runInteractiveCommand cmd1<br>
>> > err <- hGetContents hErr<br>
>> > hClose hErr<br>
>> > if null err<br>
>> > then do<br>
>> > out <- hGetContents hOut<br>
>> > mapM (f cmd2) (lines out)<br>
>> > else<br>
>> > putStr err >> exitFailure<br>
>> ><br>
>> > f :: String -> String -> IO ExitCode<br>
>> > f cmd2 item = system cmd2'<br>
>> > where cmd2' = if cmd2 =~ "\\$\\_"::Bool<br>
>> > then subRegex (mkRegex "\\$\\_") cmd2 item<br>
>> > else cmd2<br>
>> > --<br>
>> ><br>
>> > It works, except one issue that is bothering me.<br>
>> ><br>
>> > If I issue<br>
>> > mapm 'lt $_' ls,<br>
>> > I get a bunch of<br>
>> > /bin/sh: lt: command not found,<br>
>> > while I expect it act the same as<br>
>> > mapm 'ls -Alrt --color=auto $_' ls,<br>
>> > because "lt" is aliased to "ls -Alrt --color=auto."<br>
>> ><br>
>> > Notice "/bin/sh" above. My shell is actually tcsh. All the aliases are<br>
>> > in<br>
>> > ~/.cshrc.<br>
>> ><br>
>> > I tried replacing "system cmd2'" with<br>
>> > system ("source ~/.cshrc; " ++ cmd2')<br>
>> > and<br>
>> > system ("tcsh -c " ++ "'source ~/.cshrc; " ++ cmd2' ++ "'"),<br>
>> > but they did not solve the problem.<br>
>> ><br>
>> > Can someone please help me?<br>
>> ><br>
>> > Thanks,<br>
>> ><br>
>> > Hong<br>
>><br>
>> > _______________________________________________<br>
>> > Beginners mailing list<br>
>> > <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
>> > <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
>><br>
>><br>
>> _______________________________________________<br>
>> Beginners mailing list<br>
>> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
>> <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
><br>
</div></div></blockquote></div><br>