execline
Software
skarnet.org

# The `elgetpositionals` program

`elgetpositionals` substitutes the positional parameters of an execline script.

## Interface

         elgetpositionals [ -P sharp ] prog...

- `elgetpositionals` reads the number n of "positional parameters" in the `#` environment variable. If that variable is not set or does not contain a valid n, `elgetpositionals` exits 100.
- `elgetpositionals` performs some substitutions in parallel on prog...:
  - key: `#`, value: n
  - key: `0`, value: the value of the `0` environment variable
  - key: `1`, value: the value of the `1` environment variable
  - ... and so on until n (or sharp if it is greater than n). Those values are never transformed.
  - key: `@`, value: all values of the variables from `1` to `n`. This value is split into n words.
  If a variable between `0` and `n` does not exist, `elgetpositionals` exits 100.

## Options

- `-P` sharp : substitute at least sharp+1 positional parameters, from 0 to max(n, sharp). If n<sharp, positional parameters between n+1 and sharp are replaced with the empty string. Not having the `-P` switch is equivalent to having `-P 0`.

## Notes

- A typical argument-taking execline script will often begin this way:

       #!/command/execlineb
       elgetopt optstring
       elgetpositionals
       prog...

- If you are performing other substitutions that do not depend on the positional parameters, think about replacing the `elgetpositionals` call with a multisubstitute call containing the `elgetpositionals` directive.
- If you are going to use the shift command, it is best to use importas to substitute the first positional parameters, then use `shift`, then `elgetpositionals`. That way, `$@` will correctly be replaced by the remaining arguments. More generally, you should try to use `elgetpositionals` as late as possible.
- Use `execlineb`'s `-S` switch instead of `elgetpositionals` whenever you can. It is more efficient.