builtin-option
Bash read -d
Reads through the first character of delimiter instead of newline; empty delimiter selects NUL. Returns nonzero at EOF before delimiter; cannot store embedded NUL.
Formal Syntax & Structure
bash syntaxbash
IFS= read -r -d delimiter nameParameters & Attributes
| Name | Type | Description |
|---|---|---|
| delimiter | string | First character is delimiter; empty selects NUL. |
| name | identifier | Destination variable. |
Return Value
exit status
Reads through the first character of delimiter instead of newline; empty delimiter selects NUL. Returns nonzero at EOF before delimiter; cannot store embedded NUL.
Working Example
Example Snippetbash
count=0while IFS= read -r -d '' name; do count=$(( count + 1 )) printf '%q\n' "$name"done < <(printf '%s\0' 'daily report' $'two\nlines')printf 'count=%s\n' "$count"