diff --git a/SC2046.md b/SC2046.md index adca7ff..3fe5d93 100644 --- a/SC2046.md +++ b/SC2046.md @@ -31,7 +31,13 @@ In rare cases you actually want word splitting, such as in 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) ) + # For bash + mapfile -t args < <(pkg-config --libs openssl) + + # For ksh + pkg-config --libs openssl | while IFS="" read -r line; do array+=("$line"); done + + # expand args 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: