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 name

Parameters & Attributes

NameTypeDescription
delimiterstringFirst character is delimiter; empty selects NUL.
nameidentifierDestination 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"
Bash Reference