From 5ab64b0a3d166680fc4404ed65faa336a31f7179 Mon Sep 17 00:00:00 2001 From: "Pedro Arthur Duarte [aka JEdi]" Date: Thu, 14 Sep 2017 17:30:39 -0300 Subject: [PATCH] Add an example of how to avoid this warning using arrays --- SC2046.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/SC2046.md b/SC2046.md index 46a8b8f..adca7ff 100644 --- a/SC2046.md +++ b/SC2046.md @@ -29,4 +29,16 @@ In rare cases you actually want word splitting, such as in gcc $(pkg-config --libs openssl) client.c -This is because `pkg-config` outputs `-lssl -lcrypto`, which you want to break up by spaces into `-lssl` and `-lcrypto`. \ No newline at end of file +This is because `pkg-config` outputs `-lssl -lcrypto`, which you want to break up by spaces into `-lssl` and `-lcrypto`. An alternative is to put the variables to an array and expand it: + + args=( $(pkg-config --libs openssl) ) + gcc "${args[@]}" client.c + +The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments: + + compile () { + args=( $(pkg-config --libs openssl) "${@}" ) + gcc "${args[@]}" client.c + } + compile -DDEBUG + + gcc -lssl -lcrypto -DDEBUG client.c \ No newline at end of file