mirror of
https://github.com/dylanaraps/pure-bash-bible.git
synced 2025-01-17 20:28:25 +01:00
bible: Add read file method which works like mapfile. Closes #62
This commit is contained in:
parent
b713eafcbe
commit
e1c90d7590
@ -878,9 +878,14 @@ file_data="$(<"file")"
|
|||||||
Alternative to the `cat` command.
|
Alternative to the `cat` command.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# Bash <4
|
# Bash <4 (discarding empty lines).
|
||||||
IFS=$'\n' read -d "" -ra file_data < "file"
|
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+
|
# Bash 4+
|
||||||
mapfile -t file_data < "file"
|
mapfile -t file_data < "file"
|
||||||
```
|
```
|
||||||
|
@ -15,9 +15,14 @@ file_data="$(<"file")"
|
|||||||
Alternative to the `cat` command.
|
Alternative to the `cat` command.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# Bash <4
|
# Bash <4 (discarding empty lines).
|
||||||
IFS=$'\n' read -d "" -ra file_data < "file"
|
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+
|
# Bash 4+
|
||||||
mapfile -t file_data < "file"
|
mapfile -t file_data < "file"
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user