bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

read Built-in Parameter Behavior -- Null Byte Delimiter


From: Adam Danischewski
Subject: read Built-in Parameter Behavior -- Null Byte Delimiter
Date: Sat, 16 Jan 2016 14:28:27 -0500

It seems the parameter for the delimiter for the read built-in behaves differently for the NULL case, and it is a very useful case. I found this after a difficult to track down bug appeared in some of  my code, so I thought I would pass it on to you.

If it is expected behavior I didn't see it in the documents. Most other options seem to follow the getopts model and allow for no space for parameter arguments.

It seems to work for the read built-in yet not for NULL read -d''.

E.g.
$> touch file_{1..40..3}.txt
$> while IFS= read -r -d'.' a; do echo "got $a"; done < <(find . -type f -print0)
                       has the same results as
$> while IFS= read -r -d '.' a; do echo "got $a"; done < <(find . -type f -print0)
got
got /file_40
got txt
got /file_37
...
got txt
got /file_1

Yet if we look for the null byte:
$> while IFS= read -r -d'' a; do echo "got $a"; done < <(find . -type f -print0)
                       returns nothing
$> while IFS= read -r -d '' a; do echo "got $a"; done < <(find . -type f -print0)
                       returns the expected results
got ./file_40.txt
got ./file_37.txt
got ./file_34.txt
...
got ./file_16.txt



reply via email to

[Prev in Thread] Current Thread [Next in Thread]