execline: the elgetopt command
Keywords: execline command elgetopt options arguments

execline
Software
skarnet.org

# The `elgetopt` program

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

## Interface

         elgetopt 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 otherwise.
- After setting all recognized options, `elgetopt` makes new `#`, `1`, `2`... "positional parameters" with what remains.
- `elgetopt` then execs into prog....

## Notes

- GNU-style options are not supported.