Hi everybody. I found the following bug while running some of my bash scripts on GNU/Linux with stdout redirected to /dev/full, to see if write errors where correctly detected and reported.
It turned out that, on write errors, the printf builtin correctly returns a non-zero status (thus my scripts at least had a correct exit status), but unfortunately it does not always display a suitable error message on stderr; in particular, it fails to do so if the printed string does *not* end with a newline. On the contrary, the echo builtin both returns a non-zero status and write a clear error message on standard error, even if called with the `-n' option (so that the printed string does not end with a newline). Examples (tested with both bash 3.2 and bash 4.0, more details about versions and system information will follow): $ ls -l /dev/full crw-rw-rw- 1 root root 1, 7 Sep 2 18:36 /dev/full $ cat printf-bug.sh echo "* `type printf`" echo "* `type echo`" # - - - printf x >/dev/full echo a:$? printf "%s\n" x >/dev/full echo b:$? echo -n x >/dev/full echo c:$? echo x >/dev/full echo d:$? # - - - exit 0 $ bash printf-bug.sh # using either bash 4.0 or 3.2 * printf is a shell builtin * echo is a shell builtin a:1 printf-bug.sh: line 6: printf: write error: No space left on device b:1 printf-bug.sh: line 8: echo: write error: No space left on device c:1 printf-bug.sh: line 10: echo: write error: No space left on device d:1 By the way, bash 3.0 behaves far worser (I don't known if you can found this info useful, but anyway here it is): $ bash-3.0 printf-bug.sh * printf is a shell builtin * echo is a shell builtin a:0 b:0 c:1 d:1 Here are the details on my system and the bash shells used. --- Details on operating system: $ uname -s -r -m -o Linux 2.6.26-1-686 i686 GNU/Linux $ lsb_release -i -d -r -c Distributor ID: Debian Description: Debian GNU/Linux testing/unstable Release: testing/unstable Codename: n/a $ cat /etc/debian_version squeeze/sid --- Details on bash versions: Bash 4.0 --------------- Installed from debian package "bash", version "4.0-4" Complete version string: 4.0.28(1)-release Information from bashbug [Automatically generated]: Machine: i486 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2 -Wall Machine Type: i486-pc-linux-gnu Bash Version: 4.0 Patch Level: 28 Release Status: release Bash 3.2 --------------- Installed by hand from official tarball. Complete version string: 3.2.0(1)-release Information from bashbug [Automatically generated]: Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/opt/vintage/bash-3.2/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -O2 Machine Type: i686-pc-linux-gnu Bash Version: 3.2 Patch Level: 0 Release Status: release Bash 3.0 --------------- Installed by hand from official tarball. Complete version string: 3.00.0(1)-release Information from bashbug [Automatically generated]: Machine: i686 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/opt/vintage/bash-3.0/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -g -O2 Machine Type: i686-pc-linux-gnu Bash Version: 3.0 Patch Level: 0 Release Status: release --- Regards, Stefano