Node:The Top of a Script File, Next:, Up:Guile Scripts

5.2.1 The Top of a Script File

The first line of a Guile script must tell the operating system to use Guile to evaluate the script, and then tell Guile how to go about doing that. Here is the simplest case:

Guile reads the program, evaluating expressions in the order that they appear. Upon reaching the end of the file, Guile exits.

The function command-line returns the name of the script file and any command-line arguments passed by the user, as a list of strings.

For example, consider the following script file:

#!/usr/local/bin/guile -s
(write (command-line))

If you put that text in a file called foo in the current directory, then you could make it executable and try it out like this:

$ chmod a+x foo
$ ./foo
$ ./foo bar baz
("./foo" "bar" "baz")

As another example, here is a simple replacement for the POSIX echo command:

#!/usr/local/bin/guile -s
(for-each (lambda (s) (display s) (display " "))
  (cdr (command-line)))

command-line Scheme Procedure
program-arguments Scheme Procedure
Return a list of the command-line arguments passed to the currently running program. If the program invoked Guile with the -s, -c or -- switches, these procedures ignore everything up to and including those switches.