scripts on unix

Frederik Eaton frederik at a5.repetae.net
Wed Mar 14 17:53:49 EDT 2007


Scripts are tidy, since they're also a source file and you don't have
to worry about keeping a separate binary executable up to date. I'm
sure this topic has been well discussed on the vast internet. For
instance, look at Setup.hs in Cabal. That could be called a script,
because it is rarely compiled, although it doesn't have the advantage
of being executable via the kernel, which most other scripts on Unix
do.

Perhaps another important attribute of scripts is that they, or at
least the executable ones, contain instructions for running themselves
- one doesn't have to read through documentation to figure out which
command to pass the file to, in order to make it do something useful.

I think the popularity of scripts is due to the combination of these
two features: a script is a source file, and it is self-describing in
a way that the operating system can "understand".

Frederik

On Wed, Mar 14, 2007 at 08:58:33PM +0000, Seth Kurtzberg wrote:
> I compile the programs, instead of trying to run them as scripts.  Is there any reason you prefer to interpret the scripts?  I'm not saying it's not a legitimate thing to do, just wondering why you prefer to do it that way.
> 
> Seth Kurtzberg
> 
> 
> On Wed, 14 Mar 2007 19:31:55 +0000
> Frederik Eaton <frederik at a5.repetae.net> wrote:
> 
> > Hello,
> > 
> > What is the proper technique for creating a Haskell script on a Unix
> > system?
> > 
> > e.g. with Perl I do
> > 
> > #!/bin/sh
> > echo DEFANGED.348224
> > exit
> > #!/usr/bin/env perl
> > print "hello world\n";
> > 
> > or
> > 
> > #!/usr/bin/perl
> > print "hello world\n";
> > 
> > I tried
> > 
> > $ cat test
> > #!/usr/bin/env runhaskell
> > module Main where
> > main = do
> >     putStrLn "hello world"
> > 
> > But that doesn't work:
> > 
> > $ ./test
> > Warning: ignoring unrecognised input `./test'
> > 
> > <interactive>:1:73:
> >     Failed to load interface for `Main':
> >       Use -v to see a list of the files searched for.
> > 
> > When I use "runghc" I get the same error.
> > 
> > If I change the first line to "-x hs" then the error is:
> > 
> > ghc-6.6: unrecognised flags: -x hs
> > Usage: For basic information, try the `--help' option.
> > 
> > because the #! mechanism only allows a single argument. Thoughts?
> > 
> > Thanks,
> > 
> > Frederik
> > 
> > -- 
> > http://ofb.net/~frederik/
> > _______________________________________________
> > Glasgow-haskell-users mailing list
> > Glasgow-haskell-users at haskell.org
> > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
> > 
> 

-- 
http://ofb.net/~frederik/


More information about the Glasgow-haskell-users mailing list