Date: Sat, 17 Nov 2012 23:00:01 GMT From: Jilles Tjoelker <jilles@stack.nl> To: freebsd-bugs@FreeBSD.org Subject: bin/173642: ``here-document'' does not works in FreeBSD 9 /bin/sh Message-ID: <201211172300.qAHN018V074058@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/173642; it has been noted by GNATS. From: Jilles Tjoelker <jilles@stack.nl> To: bug-followup@FreeBSD.org, Aleksandr A Babaylov <"."@babolo.ru> Cc: 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 5<<EOF with 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211172300.qAHN018V074058>