[Haskell-beginners] "system" call uses a different shell, or does not pick up the whole environment

Brandon Allbery allbery.b at gmail.com
Tue Aug 28 19:12:08 CEST 2012

On Tue, Aug 28, 2012 at 10:58 AM, Hong Yang <hyangfji at 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                                      allbery.b at 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-0001.htm>

More information about the Beginners mailing list