Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  "system" call uses a different shell, or does not pick
      up the whole environment (Matthew)
   2. Re:  "system" call uses a different shell, or does not pick
      up the whole environment (Hong Yang)
   3. Re:  "system" call uses a different shell, or does not pick
      up the whole environment (Brent Yorgey)
   4. Re:  "system" call uses a different shell, or does not pick
      up the whole environment (Brandon Allbery)


----------------------------------------------------------------------

Message: 1
Date: Tue, 28 Aug 2012 08:40:09 -0700
From: Matthew <wonderzom...@gmail.com>
Subject: Re: [Haskell-beginners] "system" call uses a different shell,
        or does not pick up the whole environment
To: Hong Yang <hyang...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <cab4w-sau24kx5yrufsokeh9yntg1pizpojakjhd23-4eao1...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Not to further discourage you from experimenting, but xargs can also
run commands in parallel. Check out the -P argument. :)

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



------------------------------

Message: 2
Date: Tue, 28 Aug 2012 10:49:20 -0500
From: Hong Yang <hyang...@gmail.com>
Subject: Re: [Haskell-beginners] "system" call uses a different shell,
        or does not pick up the whole environment
To: Matthew <wonderzom...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <CA+_A4U7rDXfJ-715HzH3Lk=kvb4w8CW1ovu-F=sqvkmxkab...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Oh, yeah.

[-P max-procs]



On Tue, Aug 28, 2012 at 10:40 AM, Matthew <wonderzom...@gmail.com> wrote:

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

------------------------------

Message: 3
Date: Tue, 28 Aug 2012 12:03:28 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] "system" call uses a different shell,
        or does not pick up the whole environment
To: Matthew <wonderzom...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <20120828160328.ga4...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

Ooh, neat, I didn't even know about that option. =)

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



------------------------------

Message: 4
Date: Tue, 28 Aug 2012 13:12:08 -0400
From: Brandon Allbery <allber...@gmail.com>
Subject: Re: [Haskell-beginners] "system" call uses a different shell,
        or does not pick up the whole environment
To: Hong Yang <hyang...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <CAKFCL4XDOyCb9-dNvt5B6u+2LK+=rpgeq-fdi-un-slavo9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Aug 28, 2012 at 10:58 AM, Hong Yang <hyang...@gmail.com> wrote:

> I get a bunch of
>         /bin/sh: lt: command not found,
> while I expect it act the same as
>         mapm    'ls -Alrt --color=auto $_'    ls,
> because "lt" is aliased to "ls -Alrt --color=auto."
>
> Notice "/bin/sh" above. My shell is actually tcsh. All the aliases are in
> ~/.cshrc.
>

"system"-like functions in most languages use /bin/sh specifically,
regardless of the user's shell, because programs cannot be expected to
adapt between the different redirection commands use by sh-like and
csh-like shells.  Consistency is important here, if you run a shell command
from a program you do not want to deal with the fact that csh speaks an
incompatible language and fish uses XML, etc.

If you really want to run your/the user's shell, retrieve $SHELL from the
environment and run it directly.

    system $ "${SHELL:-/bin/sh} -c '" ++ mycommand ++ "'"

-- 
brandon s allbery                                      allber...@gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120828/65363946/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 50, Issue 34
*****************************************

Reply via email to