Added a multi-line example that works with Bash 3.x

Lachlan Donald
2018-08-21 15:41:31 +10:00
parent 341e5df2bf
commit 9c95c853d4

@@ -11,9 +11,12 @@ array=( $(mycommand) )
If it outputs multiple lines, each of which should be an element: If it outputs multiple lines, each of which should be an element:
```sh ```sh
# For bash # For bash 4.x
mapfile -t array < <(mycommand) mapfile -t array < <(mycommand)
# For bash 3.x+
while IFS=$'\n' read -r line; do array+=("$line"); done < <(mycommand)
# For ksh # For ksh
mycommand | while IFS="" read -r line; do array+=("$line"); done mycommand | while IFS="" read -r line; do array+=("$line"); done
``` ```