[Top][All Lists]

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

builtin echo command redirection misbehaves in detached scripts when ter

From: Pierre-Philippe Coupard
Subject: builtin echo command redirection misbehaves in detached scripts when terminal is closed
Date: Sun, 09 Sep 2007 16:58:23 +0200
User-agent: Thunderbird (X11/20060812)

Configuration Information [Automatically generated, do not change]:
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 uname output: Linux akula #4 Sat Sep 8 23:10:46 CEST 2007 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

Bash Version: 3.1
Patch Level: 17
Release Status: release

       With Unix-98 ptys, the builtin echo command gets executed
       even when writing to stdout or redirecting to stderr fails, and
       the output gets written to the wrong file descriptor if any other
       redirection is used in the script.

       For example, with the following script:

       while [ 1 ];do
         echo Test1
         echo Test2 >> file.txt
         sleep 1

As expected, when this script is run in the background (&), the console slowly fills with "Test1" lines, and the file.txt file slowly fills with
       "Test2" lines.

Now exit the shell leaving the script running (don't simply close the
       xterm, that'd kill the script. Type "exit"). Since the terminal has
       closed, stdout is closed, so "echo Test1" should fail. It doesn't,
instead it writes "Test1" lines into whatever open file descriptor it
       can find. In this case, file.txt starts filling up with


This does not happen with BSD-style ptys, because apparently when the
       terminal is closed, the tty seen by the detached bash script stays
       intact, and whatever is written to the now-closed terminal is simply
       discarded by the kernel, so the script keeps seeing open stdout and
stderr file descriptors. In the case of Unix-98 ptys, this bug happens
       because the tty file descriptors the bash script uses are really

This also does not happen with an external echo command: with /bin/echo,
       the redirection fails and the command is not executed, as expected.

reply via email to

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