diff --git a/sh.dol.c b/sh.dol.c
index 28e8639..362ec55 100644
--- a/sh.dol.c
+++ b/sh.dol.c
@@ -746,6 +746,7 @@ fixDolMod(void)
 
 	    if (c == 's') {	/* [eichin:19910926.0755EST] */
 		int delimcnt = 2;
+		int esc = 0;
 		eChar delim = DgetC(0);
 		Strbuf_append1(&dolmod, (Char) c);
 		Strbuf_append1(&dolmod, (Char) delim);
@@ -756,9 +757,14 @@ fixDolMod(void)
 		    break;
 		}	
 		while ((c = DgetC(0)) != DEOF) {
+		    if (esc == 0 && c == '\\') {
+			esc = 1;
+			continue;
+		    }
 		    Strbuf_append1(&dolmod, (Char) c);
-		    if (c == delim) delimcnt--;
+		    if (!esc && c == delim) delimcnt--;
 		    if (!delimcnt) break;
+		    esc = 0;
 		}
 		if (delimcnt) {
 		    seterror(ERR_BADSUBST);
diff --git a/sh.lex.c b/sh.lex.c
index 46cc96d..4277912 100644
--- a/sh.lex.c
+++ b/sh.lex.c
@@ -618,6 +618,7 @@ getdol(void)
 	    /* scan s// [eichin:19910926.0512EST] */
 	    if (c == 's') {
 		int delimcnt = 2;
+		int esc = 0;
 		eChar delim = getC(0);
 
 		Strbuf_append1(&name, delim);
@@ -627,9 +628,15 @@ getdol(void)
 		    break;
 		}
 		while ((c = getC(0)) != CHAR_ERR) {
+		    if (esc == 0 && c == '\\') {
+			esc = 1;
+			Strbuf_append1(&name, c);
+			continue;
+		    }
 		    Strbuf_append1(&name, c);
-		    if (c == delim) delimcnt--;
+		    if (!esc && c == delim) delimcnt--;
 		    if (!delimcnt) break;
+		    esc = 0;
 		}
 		if (delimcnt) {
 		    seterror(ERR_BADSUBST);
