mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Minor edits
@@ -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.
|
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 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.
|
To implement the subcommand interface, first pick a prefix like `subcommand_` below for the names of the functions 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:
|
For example:
|
||||||
```sh
|
```sh
|
||||||
@@ -58,4 +58,4 @@ main() {
|
|||||||
main foo aaa bbb
|
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 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`.
|
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 `subcommand_foo` with parameters `aaa`, `bbb`, and `ccc`.
|
Reference in New Issue
Block a user