bug-bash
[Top][All Lists]
Advanced

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

Built-in printf Sits Awkwardly with UDP.


From: Ralph Corderoy
Subject: Built-in printf Sits Awkwardly with UDP.
Date: Mon, 18 Jul 2011 15:14:23 +0100

Hi,

(I'm not subscribed to the list so please keep me CC'd.)

Consider

    printf 'foo bar\n' >/dev/udp/localhost/4242

with bash's printf built-in, it works fine.  One packet is sent.
However, make that two lines

    printf 'foo\nbar\n' >/dev/udp/localhost/4242

and two packets are sent, one per line.  If the aim is to send a string
of data in one packet this causes problems.

Using /usr/bin/printf from coreutils gives one write(2), so that's a
possible workaround.

Is this happening because the built-in printf is using putchar(3) in the
PC() macro and stdio thinks file descriptor 1 is still to a tty so it's
persisting in line buffering?  It would seem nicer if fewer write(2)s
were done when stdout isn't a tty, and not just for UDP use.

Cheers, Ralph.



reply via email to

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