diff options
author | Dylan Araps <dylan.araps@gmail.com> | 2019-09-28 19:48:19 +0300 |
---|---|---|
committer | Dylan Araps <dylan.araps@gmail.com> | 2019-09-28 19:48:19 +0300 |
commit | 9e0981752fca795a3eac87ebfac395666776e97b (patch) | |
tree | 72bc790d0a1f298435cc8e79eb1831d4253269ac | |
parent | bb10d3173c819c0b9e5fb82bbc4a2bc445706739 (diff) | |
download | pure-sh-bible-9e0981752fca795a3eac87ebfac395666776e97b.tar.gz pure-sh-bible-9e0981752fca795a3eac87ebfac395666776e97b.zip |
bible: Fix read stripping leading & trailing IFS whitespace. Closes #8
-rw-r--r-- | README.md | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -410,7 +410,7 @@ Alternative to the `head` command. ```sh head() { # Usage: head "n" "file" - while read -r line; do + while IFS= read -r line; do printf '%s\n' "$line" i=$((i+1)) [ "$i" = "$1" ] && return @@ -458,7 +458,7 @@ lines() { # 'read' exits with '1' when it sees EOL and # without the added test, the line isn't sent # to the loop. - while read -r line || [ -n "$line" ]; do + while IFS= read -r line || [ -n "$line" ]; do lines=$((lines+1)) done < "$1" @@ -647,7 +647,7 @@ done ## Loop over the contents of a file ```shell -while read -r line || [ -n "$line" ]; do +while IFS= read -r line || [ -n "$line" ]; do printf '%s\n' "$line" done < "file" ``` |