command-line - retrieve the program's command line
(import (rnrs)) ;R6RS
(import (rnrs programs)) ;R6RS
(import (scheme process-context)) ;R7RS
Returns the command line passed to the process as a list of strings. The first
element is an implementation-specific name for the running top-level program.
The remaining elements are command-line arguments according to the operating
system's conventions.
- R7RS
- It is an error to mutate any of these strings.
- Larceny
- Larceny uses "larceny" as the first element of the list.
Returns a single value which is a list of strings.
;; cmd.sps
#!/usr/bin/env scheme-script
(import (rnrs))
(write (command-line))
(newline)
;; When invoked from the shell:
$ ./cmd.sps Hello World
("./cmd.sps" "Hello" "World")
This procedure is used in programs that are invoked from the command line or
that can be customized with a command line argument. Programs meant to be
invoked from the shell can use a command line parser like SRFI-37.
The first string in the list is unreliable. Many implementations use the name of
the program file or copy the string received from the operating system, but
there exist situations where that fails, such as when execve(2) is used
with a NULL or zero-length argv.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed.
- R7RS
- The assertions described above are errors. Implementations may signal an
error, extend the procedure's domain of definition to include such
arguments, or fail catastrophically.
This procedure is new to R6RS and to R7RS. Early Scheme systems running on
MacLISP had access to (status jcl) that returned the job command line,
or the equivalent depending on which system it was running on.