[plt-scheme] getting at the name used to invoke a script

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jan 27 17:27:50 EST 2005

On Jan 27, Jim Blandy wrote:
> In the Bourne shell, a script can use $0 to access its own name:
> 
>     $ cat > hello.sh
>     #!/bin/sh
> 
>     echo "Hello, world!  I'm $0!"
>     $ chmod a+x hello.sh
>     $ ./hello.sh foo bar baz
>     Hello, world!  I'm ./hello.sh!
>     $
> 
> In MzScheme, I don't see a way to get the equivalent information.
> argv is missing the script name, and 'program' is the path to mzscheme
> itself:
> 
>     $ cat hello
>     #!/home/jimb/plt/bin/mzscheme -qr
> 
>     (write program) (newline)
>     $ ./hello
>     "/home/jimb/plt/bin/mzscheme"
>     $
> 
> Is this information available?

You can use -qC instead of -qr, which will call `main' with a list of
the script name and then other arguments.  But that comes with the
usual "$0" traps (it's like mzscheme -qr "$0" "$@").


> I understand that one can request that lots of different files be
> loaded on a single command line, but there ought to be something
> reasonable: a parameter containing the name of the file we've most
> recently begun to load, for example.

See:

  http://list.cs.brown.edu/pipermail/plt-scheme/2004-November/007288.html

for a solution (that I still didn't add to 299, BTW).

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



Posted on the users mailing list.