| www.delorie.com/gnu/docs/guile/guile_8.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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:
The operating system interprets this to mean that the rest of the line is the name of an executable that can interpret the script. Guile, however, interprets these characters as the beginning of a multi-line comment, terminated by the characters `!#' on a line by themselves. (This is an extension to the syntax described in R5RS, added to support shell scripts.)
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)) (newline) |
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")
$ ./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))) (newline) |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |