d92eec9
diff -up ksh-20120801/src/cmd/ksh93/sh/macro.c.orig ksh-20120801/src/cmd/ksh93/sh/macro.c
d92eec9
--- ksh-20120801/src/cmd/ksh93/sh/macro.c.orig	2013-12-09 13:13:22.153525239 +0100
d92eec9
+++ ksh-20120801/src/cmd/ksh93/sh/macro.c	2013-12-09 13:20:58.144635385 +0100
ebf9b31
@@ -391,7 +391,7 @@ void sh_machere(Shell_t *shp,Sfio_t *inf
ebf9b31
 				break;
ebf9b31
 			    }
ebf9b31
 			    case S_PAR:
ebf9b31
-				comsubst(mp,(Shnode_t*)0,1);
ebf9b31
+				comsubst(mp,(Shnode_t*)0,3);
ebf9b31
 				break;
ebf9b31
 			    case S_EOF:
ebf9b31
 				if((c=fcfill()) > 0)
ebf9b31
@@ -1165,7 +1165,7 @@ retry1:
ebf9b31
 	    case S_PAR:
ebf9b31
 		if(type)
ebf9b31
 			goto nosub;
ebf9b31
-		comsubst(mp,(Shnode_t*)0,1);
ebf9b31
+		comsubst(mp,(Shnode_t*)0,3);
ebf9b31
 		return(1);
ebf9b31
 	    case S_DIG:
ebf9b31
 		var = 0;
d92eec9
@@ -2152,10 +2152,12 @@ static void comsubst(Mac_t *mp,register
d92eec9
 	mp->ifsp = nv_getval(np);
d92eec9
 	stkset(stkp,savptr,savtop);
d92eec9
 	newlines = 0;
d92eec9
-	if(type/*==3 - don't break `` vs $() */ && mp->shp->spid)
d92eec9
+	if(type==3 && mp->shp->spid)
d92eec9
 	{
d92eec9
 		job_wait(mp->shp->spid);
d92eec9
-		mp->shp->spid = 0;
d92eec9
+		if(mp->shp->pipepid==mp->shp->spid)
d92eec9
+			mp->shp->spid = 0;
d92eec9
+		mp->shp->pipepid = 0;
d92eec9
 	}
d92eec9
 	sfsetbuf(sp,(void*)sp,0);
d92eec9
 	bufsize = sfvalue(sp);
d92eec9
diff -up ksh-20120801/src/cmd/ksh93/sh/subshell.c.anotherfix ksh-20120801/src/cmd/ksh93/sh/subshell.c
d92eec9
--- ksh-20120801/src/cmd/ksh93/sh/subshell.c.anotherfix	2014-01-20 14:43:46.410416327 +0100
d92eec9
+++ ksh-20120801/src/cmd/ksh93/sh/subshell.c	2014-01-20 14:43:46.444416042 +0100
ebf9b31
@@ -122,7 +122,8 @@ void	sh_subtmpfile(Shell_t *shp)
ebf9b31
 		else if(errno!=EBADF)
ebf9b31
 			errormsg(SH_DICT,ERROR_system(1),e_toomany);
ebf9b31
 		/* popping a discipline forces a /tmp file create */
ebf9b31
-		sfdisc(sfstdout,SF_POPDISC);
ebf9b31
+		if(shp->comsub != 1)
ebf9b31
+			sfdisc(sfstdout,SF_POPDISC);
ebf9b31
 		if((fd=sffileno(sfstdout))<0)
ebf9b31
 		{
ebf9b31
 			/* unable to create the /tmp file so use a pipe */
d92eec9
diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.anotherfix ksh-20120801/src/cmd/ksh93/sh/xec.c
d92eec9
--- ksh-20120801/src/cmd/ksh93/sh/xec.c.anotherfix	2014-01-20 14:47:30.527524008 +0100
d92eec9
+++ ksh-20120801/src/cmd/ksh93/sh/xec.c	2014-01-20 14:47:30.563523703 +0100
d92eec9
@@ -1773,7 +1773,11 @@ int sh_exec(register const Shnode_t *t,
ebf9b31
 					if(shp->pipepid)
ebf9b31
 						shp->pipepid = parent;
ebf9b31
 					else
ebf9b31
+					{
ebf9b31
 						job_wait(parent);
ebf9b31
+						if(parent==shp->spid)
ebf9b31
+							shp->spid = 0;
ebf9b31
+					}
ebf9b31
 					if(shp->topfd > topfd)
ebf9b31
 						sh_iorestore(shp,topfd,0);
ebf9b31
 					if(usepipe && tsetio &&  subdup && unpipe)