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