ff22b9
diff -up ksh-20120801/src/cmd/ksh93/sh/macro.c.fd2lost ksh-20120801/src/cmd/ksh93/sh/macro.c
ff22b9
--- ksh-20120801/src/cmd/ksh93/sh/macro.c.fd2lost	2014-01-22 16:23:21.211658984 +0100
ff22b9
+++ ksh-20120801/src/cmd/ksh93/sh/macro.c	2014-01-22 16:23:21.243658703 +0100
ff22b9
@@ -391,7 +391,7 @@ void sh_machere(Shell_t *shp,Sfio_t *inf
ff22b9
 				break;
ff22b9
 			    }
ff22b9
 			    case S_PAR:
ff22b9
-				comsubst(mp,(Shnode_t*)0,1);
ff22b9
+				comsubst(mp,(Shnode_t*)0,3);
ff22b9
 				break;
ff22b9
 			    case S_EOF:
ff22b9
 				if((c=fcfill()) > 0)
ff22b9
@@ -1165,7 +1165,7 @@ retry1:
ff22b9
 	    case S_PAR:
ff22b9
 		if(type)
ff22b9
 			goto nosub;
ff22b9
-		comsubst(mp,(Shnode_t*)0,1);
ff22b9
+		comsubst(mp,(Shnode_t*)0,3);
ff22b9
 		return(1);
ff22b9
 	    case S_DIG:
ff22b9
 		var = 0;
ff22b9
diff -up ksh-20120801/src/cmd/ksh93/sh/subshell.c.fd2lost ksh-20120801/src/cmd/ksh93/sh/subshell.c
ff22b9
--- ksh-20120801/src/cmd/ksh93/sh/subshell.c.fd2lost	2014-01-22 16:23:21.222658887 +0100
ff22b9
+++ ksh-20120801/src/cmd/ksh93/sh/subshell.c	2014-01-22 16:23:21.243658703 +0100
ff22b9
@@ -122,7 +122,8 @@ void	sh_subtmpfile(Shell_t *shp)
ff22b9
 		else if(errno!=EBADF)
ff22b9
 			errormsg(SH_DICT,ERROR_system(1),e_toomany);
ff22b9
 		/* popping a discipline forces a /tmp file create */
ff22b9
-		sfdisc(sfstdout,SF_POPDISC);
ff22b9
+		if(shp->comsub != 1)
ff22b9
+			sfdisc(sfstdout,SF_POPDISC);
ff22b9
 		if((fd=sffileno(sfstdout))<0)
ff22b9
 		{
ff22b9
 			/* unable to create the /tmp file so use a pipe */
ff22b9
@@ -635,6 +636,13 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
ff22b9
 		}
ff22b9
 		else
ff22b9
 		{
ff22b9
+			if(comsub!=1 && shp->spid)
ff22b9
+			{
ff22b9
+				job_wait(shp->spid);
ff22b9
+				if(shp->pipepid==shp->spid)
ff22b9
+					shp->spid = 0;
ff22b9
+				shp->pipepid = 0;
ff22b9
+			}
ff22b9
 			/* move tmp file to iop and restore sfstdout */
ff22b9
 			iop = sfswap(sfstdout,NIL(Sfio_t*));
ff22b9
 			if(!iop)
ff22b9
diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.fd2lost ksh-20120801/src/cmd/ksh93/sh/xec.c
ff22b9
--- ksh-20120801/src/cmd/ksh93/sh/xec.c.fd2lost	2014-01-22 16:23:21.237658756 +0100
ff22b9
+++ ksh-20120801/src/cmd/ksh93/sh/xec.c	2014-01-22 16:38:36.374666019 +0100
ff22b9
@@ -1756,6 +1756,8 @@ int sh_exec(register const Shnode_t *t,
ff22b9
 					nlock--;
ff22b9
 					job_unlock();
ff22b9
 				}
ff22b9
+				if(shp->subshell)
ff22b9
+					shp->spid = parent;
ff22b9
 				if(type&FPCL)
ff22b9
 					sh_close(shp->inpipe[0]);
ff22b9
 				if(type&(FCOOP|FAMP))
ff22b9
@@ -1771,7 +1773,11 @@ int sh_exec(register const Shnode_t *t,
ff22b9
 					if(shp->pipepid)
ff22b9
 						shp->pipepid = parent;
ff22b9
 					else
ff22b9
+					{
ff22b9
 						job_wait(parent);
ff22b9
+						if(parent==shp->spid)
ff22b9
+							shp->spid = 0;
ff22b9
+					}
ff22b9
 					if(shp->topfd > topfd)
ff22b9
 						sh_iorestore(shp,topfd,0);
ff22b9
 					if(usepipe && tsetio &&  subdup && unpipe)