execline
Software
skarnet.org

# The `elgetopt` program

`elgetopt` performs `getopt`-style parsing on the arguments to an execline script.

## Interface

         elgetopt [ -D default ] optstring prog...

- `elgetopt` expects to find a valid number n of arguments in the `#` environment variable, and n+1 environment variables `0`, `1`, ..., `n`. It exits 100 if it is not the case.
- `elgetopt` pushes environment variables starting with `ELGETOPT_`. To get the previous values back, use `emptyenv -o`.
- `elgetopt` looks into `1`, `2`... for options, as specified by optstring, which is a standard `getopt` string.
- If the `-c` switch is recognized, `elgetopt` sets the `ELGETOPT_c` environment variable. The value of that variable is the argument to the `-c` switch if it has one, and `1` (or default if given) otherwise.
- After setting all recognized options, `elgetopt` makes new `#`, `1`, `2`... "positional parameters" with what remains.
- `elgetopt` then execs into prog....

## Options

- `-D default` : use default as the value for the `ELGETOPT_c` environment variable if there is no argument to the `-c` switch. Default is `1`. The value is the same for all the options defined by elgetopt.

## Notes

- GNU-style options are not supported.