www.delorie.com/gnu/docs/kawa/kawa_15.html   search  
 
Buy GNU books!


Kawa, the Java-based Scheme system

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Running Command Scripts

Unix-like systems support a mechanism where a script can specify a programs that should execute it. The convention is that the first line of the file should start with the two characters `#!' followed by the absolute path of the program that should process (interpret) the script.

This is convention works well for script languages that use `#' to indicate the start of a comment, since the interpreter will automatically ignore the line specifying the interpreter filename. Scheme, however, uses `#' for various special objects, and Kawa specifically uses `#!' as a prefix for various 7.3 Special named constants such as #!optional.

Kawa does recognize the three-character sequence `#!/' at the beginning of a file as special, and ignores it. So you can specify command interpreters, as long as you don't put a space between the `#!' and the interpreter filename. Here is an example:
 
#!/usr/local/bin/kawa
(format #t "The time is ~s~%" (make <java.util.Date>))

If this file has the execute permission set and is in your PATH, then you can execute it just my naming it on command line. The system kernel will automatically execute kawa, passing it the filename as an argument.

Note that the full path-name of the kawa interpreter must be hard-wired into the script. This means you may have to edit the script depending on where Kawa is installed on your system. Another possible problem is that the interpreter must be an actual program, not a shell script. Depending on how you configure and install Kawa, kawa can be a real program or a script. You can avoid both problems by the env program, available on most modern Unix-like systems:

 
#!/usr/bin/env kawa
(format #t "The time is ~s~%" (make <java.util.Date>))


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003