bin/173642: ``here-document'' does not works in FreeBSD 9 /bin/sh

Jilles Tjoelker jilles at
Sat Nov 17 23:00:01 UTC 2012

The following reply was made to PR bin/173642; it has been noted by GNATS.

From: Jilles Tjoelker <jilles at>
To: bug-followup at, Aleksandr A Babaylov <".">
Subject: bin/173642: ``here-document'' does not works in FreeBSD 9 /bin/sh
Date: Sat, 17 Nov 2012 23:51:54 +0100

 In PR bin/173642:
 > As of FreeBSD 9.0, the below script fails (with fdescfs mounted):
 > 5<<EOF
 > foo
 > EOF
 > cat /dev/fd/5
 This script took advantage of a bug in sh that has been fixed. A
 redirection should only apply for the duration of the command it is
 attached to, except if that command is the builtin "exec". This includes
 commands consisting solely of redirections (here-documents or other
 kinds). Before 9.0, sh did not handle this properly if the fd was not
 open before a redirection attached to some kinds of commands.
 Note that the script will not work even with the older sh if fd 5 is
 already open, for example
   sh your-script 5</dev/null
 The fix is to replace the line
   exec 5<<EOF
 This will also work with the older sh, fixing the problems if fd 5 is
 already open.
 I do not plan to merge the bugfix in sh to stable/8.
 Jilles Tjoelker

More information about the freebsd-bugs mailing list