[Whonix-devel] [Help-bash] Why read exits non-zero? How to safely use bash's built-in read command?

Chet Ramey chet.ramey at case.edu
Mon Oct 7 15:43:45 CEST 2019


On 10/7/19 2:47 AM, Patrick Schleizer wrote:

> #!/bin/bash
> 
> set -e
> 
> test -f ./advancedsettings.ico
> 
> while IFS= read -r -d '' line; do
>    echo "$line"
>    IFS= read -r -d '' first_word _ <<< "$line"
>    echo "$first_word"
> done < "./advancedsettings.ico"

Think about this. The first read guarantees that the value of `line' will
not contain a NUL, since you use that as the delimiter. Why, then, would
you expect a NUL when you use the value in a here-string?

Since there's no NUL, reading the here-string will always return EOF before
hitting the delimiter, causing read to return 1.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet at case.edu    http://tiswww.cwru.edu/~chet/


More information about the Whonix-devel mailing list