Subject: bin/2384: /bin/sh does \ wrong in single quotes in backquotes
To: None <gnats-bugs@NetBSD.ORG>
From: None <cgd+@cs.cmu.edu>
List: netbsd-bugs
Date: 05/08/1996 21:21:08
>Number:         2384
>Category:       bin
>Synopsis:       /bin/sh does \<newline> wrong in single quotes in backquotes
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May  8 21:35:03 1996
>Last-Modified:
>Originator:     Chris G. Demetriou
>Organization:
Kernel Hackers 'r' Us
>Release:        NetBSD-current as of May 8, 1996
>Environment:
System: NetBSD bunnahabhain.pdl.cs.cmu.edu 1.1B NetBSD 1.1B (BUNNY) #33: Wed May 8 18:17:05 EDT 1996 cgd@bunnahabhain.pdl.cs.cmu.edu:/usr/src/sys/arch/alpha/compile/BUNNY alpha


>Description:
	NetBSD's /bin/sh handles commands like:

	foo=`echo 'foo \
            bar'`

	incorrectly.  For that example, it will assign a value of "foo \ bar"
	to the variable foo.

	This conflicts with other sh implementations on other systems,
	as well as (pd)ksh, bash, etc., which all remove the backslash.

>How-To-Repeat:
	Try:

	foo=`echo 'foo \
	    bar'`
	echo $foo

	with your favorite 'sh' lookalikes, or try the handy script:

#!/bin/sh

for shell in /bin/sh /usr/src/bin/sh/obj/sh bash ksh; do
echo "output from $shell:"
$shell << "__EOF__"

	# THE FOLLOWING ASSIGNMENT TRIGGERS THE BUG
	foo=`echo 'foo \
	    bar'`
	echo $foo

__EOF__
echo ""
done

	which will show you output from several shells...

>Fix:
	The following patch appears to fix the problem, and appears
	logically correct.  I've not had a chance to verify its
	correct operation with lots of shell scripts, though.  However,
	it does survive a 'configure' run, that previously failed
	because of the bug reported by this PR.

Index: parser.c
===================================================================
RCS file: /a/cvsroot/src/bin/sh/parser.c,v
retrieving revision 1.28
diff -c -r1.28 parser.c
*** parser.c	1996/03/05 21:04:00	1.28
--- parser.c	1996/05/09 01:14:04
***************
*** 1280,1285 ****
--- 1280,1292 ----
  						setprompt(2);
  					else
  						setprompt(0);
+ 					/*
+ 					 * If eating a newline, avoid putting
+ 					 * the newline into the new character
+ 					 * stream (via the STPUTC after the
+ 					 * switch).
+ 					 */
+ 					continue;
  				}
                                  if (c != '\\' && c != '`' && c != '$'
                                      && (!dblquote || c != '"'))
>Audit-Trail:
>Unformatted: