04e570f
diff -up ksh-20120801/src/cmd/ksh93/sh/macro.c.fd2lost ksh-20120801/src/cmd/ksh93/sh/macro.c
04e570f
--- ksh-20120801/src/cmd/ksh93/sh/macro.c.fd2lost	2014-01-22 16:23:21.211658984 +0100
04e570f
+++ ksh-20120801/src/cmd/ksh93/sh/macro.c	2014-01-22 16:23:21.243658703 +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;
04e570f
diff -up ksh-20120801/src/cmd/ksh93/sh/subshell.c.fd2lost ksh-20120801/src/cmd/ksh93/sh/subshell.c
04e570f
--- ksh-20120801/src/cmd/ksh93/sh/subshell.c.fd2lost	2014-01-22 16:23:21.222658887 +0100
04e570f
+++ ksh-20120801/src/cmd/ksh93/sh/subshell.c	2014-01-22 16:23:21.243658703 +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 */
04e570f
@@ -635,6 +636,13 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
04e570f
 		}
04e570f
 		else
04e570f
 		{
04e570f
+			if(comsub!=1 && shp->spid)
04e570f
+			{
04e570f
+				job_wait(shp->spid);
04e570f
+				if(shp->pipepid==shp->spid)
04e570f
+					shp->spid = 0;
04e570f
+				shp->pipepid = 0;
04e570f
+			}
04e570f
 			/* move tmp file to iop and restore sfstdout */
04e570f
 			iop = sfswap(sfstdout,NIL(Sfio_t*));
04e570f
 			if(!iop)
04e570f
diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.fd2lost ksh-20120801/src/cmd/ksh93/sh/xec.c
04e570f
--- ksh-20120801/src/cmd/ksh93/sh/xec.c.fd2lost	2014-01-22 16:23:21.237658756 +0100
04e570f
+++ ksh-20120801/src/cmd/ksh93/sh/xec.c	2014-01-22 16:38:36.374666019 +0100
04e570f
@@ -1756,6 +1756,8 @@ int sh_exec(register const Shnode_t *t,
04e570f
 					nlock--;
04e570f
 					job_unlock();
04e570f
 				}
04e570f
+				if(shp->subshell)
04e570f
+					shp->spid = parent;
04e570f
 				if(type&FPCL)
04e570f
 					sh_close(shp->inpipe[0]);
04e570f
 				if(type&(FCOOP|FAMP))
04e570f
@@ -1771,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)