[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read Built-in Parameter Behavior -- Null Byte Delimiter
From: |
Martijn Dekker |
Subject: |
Re: read Built-in Parameter Behavior -- Null Byte Delimiter |
Date: |
Sun, 17 Jan 2016 01:02:11 +0100 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 |
Adam Danischewski schreef op 16-01-16 om 20:28:
> Yet if we look for the null byte:
bash, like most UNIX shells, cannot store or handle null bytes. (zsh is
the only exception I know of.)
> $> while IFS= read -r -d'' a; do echo "got $a"; done < <(find . -type f
> -print0)
> * returns nothing *
This is because of how shell quoting works. The "read" command doesn't
even enter into it. It's all happening before "read" is even executed.
'' does not represent a null byte; it's an empty, as in zero bytes,
surrounded by single quotes.
Before passing the arguments to the command (such as 'read'), the shell
performs quote removal. This removes the quotes from the empty.
That leaves the 'read' command with no way to distinguish between
read -r -d'' a
and
read -r -d a
Meaning, you were actually executing "read" with "a" as the delimiter,
and no variable, so your "echo" command naturally returned nothing.
Meanwhile "read" would have stored whatever it got in the variable REPLY
by default.
Separating the quoted empty from the -d makes it possible to distinguish
it as an empty argument (which is still different from a null byte).
Hope this helps.
- M.
- read Built-in Parameter Behavior -- Null Byte Delimiter, Adam Danischewski, 2016/01/16
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Piotr Grzybowski, 2016/01/16
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter,
Martijn Dekker <=
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Greg Wooledge, 2016/01/18
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Chet Ramey, 2016/01/18
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Greg Wooledge, 2016/01/18
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Chet Ramey, 2016/01/18
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Adam Danischewski, 2016/01/19
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Greg Wooledge, 2016/01/19
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Adam Danischewski, 2016/01/19
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Greg Wooledge, 2016/01/19
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Reuti, 2016/01/25
- Re: read Built-in Parameter Behavior -- Null Byte Delimiter, Greg Wooledge, 2016/01/25