dc1902
diff -up ksh-20120801/src/cmd/ksh93/sh/xec.c.hokaido ksh-20120801/src/cmd/ksh93/sh/xec.c
dc1902
--- ksh-20120801/src/cmd/ksh93/sh/xec.c.hokaido	2014-09-18 14:41:57.696756230 +0200
dc1902
+++ ksh-20120801/src/cmd/ksh93/sh/xec.c	2014-09-18 14:43:55.439205247 +0200
dc1902
@@ -1633,12 +1633,20 @@ int sh_exec(register const Shnode_t *t,
dc1902
 #endif /* SHOPT_COSHELL */
dc1902
 			if(shp->subshell)
dc1902
 			{
dc1902
+				int comsubsave = shp->comsub;
dc1902
+				if(comsubsave==1)
dc1902
+					shp->comsub = 2;
dc1902
 				sh_subtmpfile(shp);
dc1902
+				shp->comsub = comsubsave;
dc1902
+				if(shp->comsub==1 && (!(shp->fdstatus[1]&IONOSEEK)))
dc1902
+					unpipe = iousepipe(shp);
dc1902
+
dc1902
 				if((type&(FAMP|TFORK))==(FAMP|TFORK))
dc1902
 				{
dc1902
 					if(shp->comsub && !(shp->fdstatus[1]&IONOSEEK))
dc1902
 					{
dc1902
-						unpipe = iousepipe(shp);
dc1902
+						if (!unpipe)
dc1902
+							unpipe = iousepipe(shp);
dc1902
 						sh_subfork();
dc1902
 					}
dc1902
 				}
dc1902
@@ -2107,7 +2115,11 @@ int sh_exec(register const Shnode_t *t,
dc1902
 			job.curjobid = 0;
dc1902
 			if(shp->subshell)
dc1902
 			{
dc1902
+				int comsubsave = shp->comsub;
dc1902
+				if(comsubsave==1)
dc1902
+					shp->comsub = 2;
dc1902
 				sh_subtmpfile(shp);
dc1902
+				shp->comsub = comsubsave;
dc1902
 				if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK))
dc1902
 					iousepipe(shp);
dc1902
 			}