add example to read lines, as opposed to just the first line with the existing example

Jonathan Zacsh
2022-06-17 16:43:34 -05:00
parent 90cca02015
commit 147787416b

@@ -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
```