From 9c95c853d47cd7c498e1daffe00fafe3ec10679b Mon Sep 17 00:00:00 2001 From: Lachlan Donald Date: Tue, 21 Aug 2018 15:41:31 +1000 Subject: [PATCH] Added a multi-line example that works with Bash 3.x --- SC2207.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SC2207.md b/SC2207.md index 2a67e21..5c87a74 100644 --- a/SC2207.md +++ b/SC2207.md @@ -11,9 +11,12 @@ array=( $(mycommand) ) If it outputs multiple lines, each of which should be an element: ```sh -# For bash +# For bash 4.x mapfile -t array < <(mycommand) +# For bash 3.x+ +while IFS=$'\n' read -r line; do array+=("$line"); done < <(mycommand) + # For ksh mycommand | while IFS="" read -r line; do array+=("$line"); done ```