[Haskell-cafe] Re: Reading files efficiently

Pete Chown 1 at 234.cx
Fri Mar 24 07:34:30 EST 2006

Simon Marlow wrote:

> GHC 6.6 will allow this, because we added the -x flag (works just like 
> gcc's -x flag).  eg. "ghc -x hs foo.wibble" will interpret foo.wibble as 
> a .hs file.  I have an uncommitted patch for runghc that uses -x, I need 
> to test & commit it.

Ah, that will be very useful, thanks!

You may already know this, but there is an oddity with shellscripts that 
can make it difficult to pass flags like -x in a useful way.  It's 
easiest to show this by an example.  First create a shellscript called 
bar, containing one line:

#!./foo -x -y

Now create foo from foo.c:

#include <stdio.h>

extern int
main (int argc, char *argv[])
   int i;

   for (i = 0; i < argc; i++)
     printf ("argv[%d] = %s\n", i, argv[i]);

Now run bar:

$ ./bar -a -b
argv[0] = ./foo
argv[1] = -x -y
argv[2] = ./bar
argv[3] = -a
argv[4] = -b

Notice how -x and -y have ended up in the same element of argv even 
though they were meant to be separate arguments.  -a and -b were fine 
because that line was processed by the shell, which saw the space 
between them and split them up.  -x and -y were not processed by the 
shell, and the kernel is unintelligent about command lines.  Everything 
after the command name ends up in a single argument.

Of course this isn't a disaster, it just means that programs which 
accept arguments in the #! line have to be careful how they parse them.


More information about the Haskell-Cafe mailing list