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