From 147787416b3d811681350c906951b473582d03e5 Mon Sep 17 00:00:00 2001 From: Jonathan Zacsh Date: Fri, 17 Jun 2022 16:43:34 -0500 Subject: [PATCH] add example to read lines, as opposed to just the first line with the existing example --- SC2046.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SC2046.md b/SC2046.md index 1906172..dbe8e67 100644 --- a/SC2046.md +++ b/SC2046.md @@ -41,9 +41,11 @@ This is because `pkg-config` outputs `-lssl -lcrypto`, which you want to break u A bash alternative in these cases is to use `read -a` for words or `mapfile` for lines. ksh can also use `read -a`, or a `while read` loop for lines. In this case, since `pkg-config` outputs words, you could use: ```sh -# Read words into an array in bash and ksh +# Read words from one line into an array in bash and ksh, then expand each as args read -ra args < <(pkg-config --libs openssl) +gcc "${args[@]}" client.c # expand as args -# expand args -gcc "${args[@]}" client.c +# Read lines into an array, then expand each as args +readarray -t file_args < <(find /etc/ -type f | grep some-check) +your-linter.sh "${file_args[@]}" # expand as args ``` \ No newline at end of file