[Haskell] ANNOUNCE: HsUnix 1.0.1 - Haskell for Unix Shell Scripting

Volker Wysk post at volker-wysk.de
Mon Feb 9 19:16:09 EST 2004

> On Mon, Feb 09, 2004 at 12:49:28PM +0100, Tomasz Zielonka wrote:
>     #!/bin/sh -e
>     cat nosuchfile | echo hello
> This script will exit with status 0 (success).  If you think about
> how traditional unix shells are implemented, you will see that they
> can't get this right.  (Which proves the non-existence of reliable
> non-trivial shell scripts!)
> I have my own half-finished shell-in-Haskell that handles this.  I
> would be interested to know whether HsUnix does.

The equivalent HsUnix script looks like this:

  import HsUnix

  main = mainwrapper $
     call (execp "cat" ["nosuchfile"] -|- execp "echo" ["hello"])

This happens to work right. The error is reported via a dynamic exception:

  ~/src/hsunix/build $ ./test2
  cat: nosuchfilehello
  : No such file or directory
  Process error. process status = Exited (ExitFailure 1)

However, when using pipes, the exitcode of only one of the involved
processes can be monitored. The other ones will be silently ignored. If
the second process would fail in the above pipe, rather than the first
one, no error would be reported. In this case, you could use "-|=" instead
of "-|-". Then the second process would be monitored.


Volker Wysk <post at volker-wysk.de>

More information about the Haskell mailing list