Next: , Previous: , Up: Kawa Scheme   [Contents][Index]


18.6.8.4 Sending Options to Kawa in a Command Script

If you need to specify extra arguments to kawa, you can run arbitrary shell commands inside Scheme block comments.

#!/bin/sh
#|
exec kawa out:base=16 out:radix=yes "$0" "$*"
|#
(format #t "The command-line is:~{ ~w~}.~%" (command-line))
(display "It has ")
(display (apply + (map string-length (command-line))))
(display " characters.")
(newline)

The trick is to hide the shell code from Kawa inside a ‘#|...|#’ block-comment. The start of the block comment is a line starting with a ‘#’, so it is treated as a comment by the shell. You can then invoke kawa (or java directly) as you prefer, setting up class-path and jars as needed, and passing whatever arguments you want. You need to make sure the shell finishes before it reaches the end of the block comment or the Scheme code, which would confuse it.

Using comments this way has the advantage that you have the option of running the script “manually” if you prefer:

$ kawa /tmp/scm-echo out:base=8 "x y"
The command-line is: "/tmp/scm-echo" "out:base=8" "x y".
It has 26 characters.