mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
add example to read lines, as opposed to just the first line with the existing example
@@ -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:
|
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
|
```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)
|
read -ra args < <(pkg-config --libs openssl)
|
||||||
|
gcc "${args[@]}" client.c # expand as args
|
||||||
|
|
||||||
# expand args
|
# Read lines into an array, then expand each as args
|
||||||
gcc "${args[@]}" client.c
|
readarray -t file_args < <(find /etc/ -type f | grep some-check)
|
||||||
|
your-linter.sh "${file_args[@]}" # expand as args
|
||||||
```
|
```
|
Reference in New Issue
Block a user