Next: Exiting from Scripts, Previous: Poke Scripts, Up: Writing Binary Utilities [Contents][Index]
When a Poke script is executed, the command line arguments passed to the script become available in the array argv. Example:
#!/usr/bin/poke -L !# for (arg in argv) print "Argument: " + arg + "\n";
Executing this script results in:
$ ./printargs foo bar 'baz quux' Argument: foo Argument: bar Argument: baz quux
Note how it is not needed to have an argc variable, since the number
of elements stored in a Poke array can be queried using an attribute:
argv'length
.
Note also that argv
is only defined when poke runs as an
interpreter:
$ poke [...] (poke) argv <stdin>:1:1: error: undefined variable 'argv' argv; ^~~~
Accessing the argv
is more than enough for many simple
programs. However, we may need a more sophisticated handling of
command-line options: support for both short and long style options,
adherence to the GNU coding standards, and the like. For these cases
poke provides a pickle argp
. See argp.