bible: Add read file method which works like mapfile. Closes #62

This commit is contained in:
Dylan Araps 2019-09-19 16:34:18 +03:00
parent b713eafcbe
commit e1c90d7590
2 changed files with 12 additions and 2 deletions

View File

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

View File

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