[plt-scheme] Finding out the script name

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Feb 17 07:33:52 EST 2003

On Feb 17, Grzegorz Chrupala wrote:
> > `argv' will contain it, but by the time the script is loaded, it will
> > be processed and will hold only the arguments that were actually
> > passed to the script, assuming it was invoked in some way like
> >
> >   #!/bin/sh
> >   #|
> >   exec mzscheme -r "$0" "$@"
> >   |#
> >   ...
> I was actually invoking it directly
> 
> #!/usr/local/bin/mzscheme -qr
> (display argv)

IMO, the above is much better -- it searches the path, it can handle
the executable being a script, it can handle any number of arguments
or any command line at all, and it gives you a nice place to run shell
commands before you start mzscheme (like "exec sudo mzscheme -r").

[The only very minor penalty is speed, but in all my scheme scripting,
I didn't find any situation where this was a problem (it's not
something you notice for interactive usage, and if you want to run a
script many times then you should do the external loop in Scheme
too).]

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.