Minor edits

jzinn
2018-06-04 21:40:17 -07:00
parent 3dea969a09
commit 7ec0df9cbc

@@ -26,7 +26,7 @@ If the intention is to provide each array element as a separate argument, put th
Concatenating a string with an array can be used to make a command line interface with subcommands.
To implement the subcommand interface, first pick a prefix like `subcommand_` below for the function names that implement the subcommands. Then protect the parsing of the subcommands by listing them in the patterns of a case statement. In the body of the case statement, a concatenation of the prefix with `"$@"` will invoke the subcommand function and pass the rest of the parameters to the function.
To implement the subcommand interface, first pick a prefix like `subcommand_` below for the function names that implement the subcommands. Then protect the parsing of the subcommands by listing them as patterns of a case statement. In the body of the case statement, a concatenation of the prefix with `"$@"` will invoke the subcommand function and pass the rest of the parameters to the function.
For example:
```sh
@@ -58,4 +58,4 @@ main() {
main foo aaa bbb
```
In the above example, inside the `main` function, the value of `"$@"` is `( foo aaa bbb ccc )`. The value of `subcommand_"$@"` after expanding is `( subcommand_foo aaa bbb ccc )`, which the shell interprets as a call to the `subcommand_foo` function.
In the above example, inside the `main` function, the value of `"$@"` is `( foo aaa bbb ccc )`. The value of `subcommand_"$@"` after expansion is `( subcommand_foo aaa bbb ccc )`, which the shell interprets as a call to the `subcommand_foo` function with parameters `aaa`, `bbb`, and `ccc`.