$ printf 'x\ny:' | ksh -c 'IFS= read -rd : -n2 a; printf "<%s>\n" "$a"'
<x>
That still reads 2 bytes off a line, a newline-delimited record, not a : delimited record here.
I know that's how it's currently documented, but that's less useful and I don't expect changing that would break backward compatibility (you wouldn't use -d and still expect line-oriented input).
A few shells have copied ksh93's -n and -d and all read those bytes (characters in the case of bash) up to the delimiter specified with -d:
$ printf 'x\ny:' | bash -c 'IFS= read -rd : -n2 a; printf "<%s>\n" "$a"'
<x
>
$ printf 'x\ny:' | mksh -c 'IFS= read -rd : -n2 a; printf "<%s>\n" "$a"'
<x
>
$ printf 'x\ny:' | busybox sh -c 'IFS= read -rd : -n2 a; printf "<%s>\n" "$a"'
<x
>
That still reads 2 bytes off a line, a newline-delimited record, not a
:delimited record here.I know that's how it's currently documented, but that's less useful and I don't expect changing that would break backward compatibility (you wouldn't use -d and still expect line-oriented input).
A few shells have copied ksh93's
-nand-dand all read those bytes (characters in the case of bash) up to the delimiter specified with-d: