mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Improve command line build examples
@@ -44,20 +44,25 @@ Sometimes you want to split on spaces, like when building a command line:
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
options="-j 5 -B"
|
options="-j 5 -B"
|
||||||
|
[[ $debug == "yes" ]] && options="$options -d"
|
||||||
make $options file
|
make $options file
|
||||||
```
|
```
|
||||||
|
|
||||||
Just quoting this doesn't work. Instead, you should have used an array (bash, ksh, zsh):
|
Just quoting this doesn't work. Instead, you should have used an array (bash, ksh, zsh):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
options=(-j 5 -B) # ksh: set -A options -- -j 5 -B
|
options=(-j 5 -B) # ksh88: set -A options -- -j 5 -B
|
||||||
|
[[ $debug == "yes" ]] && options=("${options[@]}" -d)
|
||||||
make "${options[@]}" file
|
make "${options[@]}" file
|
||||||
```
|
```
|
||||||
|
|
||||||
or a function (POSIX):
|
or a function (POSIX):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make_with_flags() { make -j 5 -B "$@"; }
|
make_with_flags() {
|
||||||
|
[ "$debug" = "yes" ] && set -- -d "$@"
|
||||||
|
make -j 5 -B "$@"
|
||||||
|
}
|
||||||
make_with_flags file
|
make_with_flags file
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user