From 304b92456fae83b928f53040ce3cac71dd2ed6ae Mon Sep 17 00:00:00 2001 From: Koichi Nakashima Date: Mon, 27 Sep 2021 01:46:07 +0900 Subject: [PATCH] Improve command line build examples --- SC2086.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SC2086.md b/SC2086.md index d1650e4..dfd67a4 100644 --- a/SC2086.md +++ b/SC2086.md @@ -44,20 +44,25 @@ Sometimes you want to split on spaces, like when building a command line: ```sh options="-j 5 -B" +[[ $debug == "yes" ]] && options="$options -d" make $options file ``` Just quoting this doesn't work. Instead, you should have used an array (bash, ksh, zsh): ```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 ``` or a function (POSIX): ```sh -make_with_flags() { make -j 5 -B "$@"; } +make_with_flags() { + [ "$debug" = "yes" ] && set -- -d "$@" + make -j 5 -B "$@" +} make_with_flags file ```