mirror of
https://github.com/dylanaraps/pure-bash-bible.git
synced 2025-08-19 14:01:23 +02:00
bible: Add read file method which works like mapfile. Closes #62
This commit is contained in:
@@ -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"
|
||||
```
|
||||
|
@@ -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"
|
||||
```
|
||||
|
Reference in New Issue
Block a user