From e1c90d75907dfeb181b54752bf810d1230aedf73 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 19 Sep 2019 16:34:18 +0300 Subject: [PATCH] bible: Add read file method which works like mapfile. Closes #62 --- README.md | 7 ++++++- manuscript/chapter4.txt | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8654357..bca6048 100644 --- a/README.md +++ b/README.md @@ -878,9 +878,14 @@ file_data="$(<"file")" Alternative to the `cat` command. ```shell -# Bash <4 +# Bash <4 (discarding empty lines). IFS=$'\n' read -d "" -ra file_data < "file" +# Bash <4 (preserving empty lines). +while read -r line; do + file_data+=("$line") +done < "file" + # Bash 4+ mapfile -t file_data < "file" ``` diff --git a/manuscript/chapter4.txt b/manuscript/chapter4.txt index e7bb50a..902fec6 100644 --- a/manuscript/chapter4.txt +++ b/manuscript/chapter4.txt @@ -15,9 +15,14 @@ file_data="$(<"file")" Alternative to the `cat` command. ```shell -# Bash <4 +# Bash <4 (discarding empty lines). IFS=$'\n' read -d "" -ra file_data < "file" +# Bash <4 (preserving empty lines). +while read -r line; do + file_data+=("$line") +done < "file" + # Bash 4+ mapfile -t file_data < "file" ```