Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.46
diff -p -u -r1.46 emacs.c
--- emacs.c	10 Jun 2012 10:15:01 -0000	1.46
+++ emacs.c	26 Nov 2012 14:25:51 -0000
@@ -399,7 +399,8 @@ x_insert(int c)
 	 *  Should allow tab and control chars.
 	 */
 	if (c == 0) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	str[0] = c;
@@ -421,7 +422,8 @@ static int
 x_do_ins(const char *cp, int len)
 {
 	if (xep+len >= xend) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return -1;
 	}
 
@@ -477,7 +479,8 @@ x_del_back(int c)
 	int col = xcp - xbuf;
 
 	if (col == 0) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	if (x_arg > col)
@@ -493,7 +496,8 @@ x_del_char(int c)
 	int nleft = xep - xcp;
 
 	if (!nleft) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	if (x_arg > nleft)
@@ -592,7 +596,8 @@ x_bword(void)
 	char	*cp = xcp;
 
 	if (cp == xbuf) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return 0;
 	}
 	while (x_arg--) {
@@ -616,7 +621,8 @@ x_fword(void)
 	char	*cp = xcp;
 
 	if (cp == xep) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return 0;
 	}
 	while (x_arg--) {
@@ -706,7 +712,8 @@ x_mv_back(int c)
 	int col = xcp - xbuf;
 
 	if (col == 0) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	if (x_arg > col)
@@ -721,7 +728,8 @@ x_mv_forw(int c)
 	int nleft = xep - xcp;
 
 	if (!nleft) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	if (x_arg > nleft)
@@ -741,7 +749,8 @@ x_search_char_forw(int c)
 		if (c < 0 ||
 		    ((cp = (cp == xep) ? NULL : strchr(cp + 1, c)) == NULL &&
 		    (cp = strchr(xbuf, c)) == NULL)) {
-			x_e_putc(BEL);
+			if (!Flag(FNOBEEP))
+				x_e_putc(BEL);
 			return KSTD;
 		}
 	}
@@ -760,7 +769,8 @@ x_search_char_back(int c)
 			if (p-- == xbuf)
 				p = xep;
 			if (c < 0 || p == cp) {
-				x_e_putc(BEL);
+				if (!Flag(FNOBEEP))
+					x_e_putc(BEL);
 				return KSTD;
 			}
 			if (*p == c)
@@ -818,7 +828,8 @@ x_load_hist(char **hp)
 	int	oldsize;
 
 	if (hp < history || hp > histptr) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return;
 	}
 	x_histp = hp;
@@ -902,7 +913,8 @@ x_search_hist(int c)
 			/* add char to pattern */
 			/* overflow check... */
 			if (p >= &pat[sizeof(pat) - 1]) {
-				x_e_putc(BEL);
+				if (!Flag(FNOBEEP))
+					x_e_putc(BEL);
 				continue;
 			}
 			*p++ = c, *p = '\0';
@@ -943,7 +955,8 @@ x_search(char *pat, int sameline, int of
 			return i;
 		}
 	}
-	x_e_putc(BEL);
+	if (!Flag(FNOBEEP))
+		x_e_putc(BEL);
 	x_histp = histptr;
 	return -1;
 }
@@ -1082,11 +1095,13 @@ x_transpose(int c)
 	 * to the one they want.
 	 */
 	if (xcp == xbuf) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	} else if (xcp == xep || Flag(FGMACS)) {
 		if (xcp - xbuf == 1) {
-			x_e_putc(BEL);
+			if (!Flag(FNOBEEP))
+				x_e_putc(BEL);
 			return KSTD;
 		}
 		/* Gosling/Unipress emacs style: Swap two characters before the
@@ -1207,7 +1222,8 @@ x_abort(int c)
 static int
 x_error(int c)
 {
-	x_e_putc(BEL);
+	if (!Flag(FNOBEEP))
+		x_e_putc(BEL);
 	return KSTD;
 }
 
@@ -1624,7 +1640,8 @@ x_kill_region(int c)
 	char	*xr;
 
 	if (xmp == NULL) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	if (xmp > xcp) {
@@ -1646,7 +1663,8 @@ x_xchg_point_mark(int c)
 	char	*tmp;
 
 	if (xmp == NULL) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	tmp = xmp;
@@ -1749,7 +1767,8 @@ x_expand(int c)
 	    &start, &end, &words, &is_command);
 
 	if (nwords == 0) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 
@@ -1758,7 +1777,8 @@ x_expand(int c)
 	for (i = 0; i < nwords;) {
 		if (x_escape(words[i], strlen(words[i]), x_emacs_putbuf) < 0 ||
 		    (++i < nwords && x_ins(space) < 0)) {
-			x_e_putc(BEL);
+			if (!Flag(FNOBEEP))
+				x_e_putc(BEL);
 			return KSTD;
 		}
 	}
@@ -1782,7 +1802,8 @@ do_complete(int flags,	/* XCF_{COMMAND,F
 	    &start, &end, &words, &is_command);
 	/* no match */
 	if (nwords == 0) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return;
 	}
 
@@ -1947,7 +1968,8 @@ x_set_arg(int c)
 	for (; c >= 0 && isdigit(c); c = x_e_getc(), first = 0)
 		n = n * 10 + (c - '0');
 	if (c < 0 || first) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		x_arg = 1;
 		x_arg_defaulted = 1;
 	} else {
@@ -1969,7 +1991,8 @@ x_comment(int c)
 	int ret = x_do_comment(xbuf, xend - xbuf, &len);
 
 	if (ret < 0)
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 	else {
 		xep = xbuf + len;
 		*xep = '\0';
@@ -2005,7 +2028,8 @@ x_prev_histword(int c)
 
 	cp = *histptr;
 	if (!cp)
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 	else if (x_arg_defaulted) {
 		rcp = &cp[strlen(cp) - 1];
 		/*
@@ -2082,7 +2106,8 @@ x_fold_case(int c)
 	char *cp = xcp;
 
 	if (cp == xep) {
-		x_e_putc(BEL);
+		if (!Flag(FNOBEEP))
+			x_e_putc(BEL);
 		return KSTD;
 	}
 	while (x_arg--) {
Index: misc.c
===================================================================
RCS file: /cvs/src/bin/ksh/misc.c,v
retrieving revision 1.37
diff -p -u -r1.37 misc.c
--- misc.c	19 Apr 2009 20:34:05 -0000	1.37
+++ misc.c	26 Nov 2012 14:25:51 -0000
@@ -140,6 +140,7 @@ const struct option options[] = {
 #else /* JOBS */
 	{ (char *) 0,	'm',		     0 }, /* so FMONITOR not ifdef'd */
 #endif /* JOBS */
+	{ "nobeep",	0,		OF_ANY },
 	{ "noclobber",	'C',		OF_ANY },
 	{ "noexec",	'n',		OF_ANY },
 	{ "noglob",	'f',		OF_ANY },
Index: sh.h
===================================================================
RCS file: /cvs/src/bin/ksh/sh.h,v
retrieving revision 1.31
diff -p -u -r1.31 sh.h
--- sh.h	10 Sep 2012 01:25:30 -0000	1.31
+++ sh.h	26 Nov 2012 14:25:51 -0000
@@ -185,6 +185,7 @@ enum sh_flag {
 	FLOGIN,		/* -l: a login shell */
 	FMARKDIRS,	/* mark dirs with / in file name completion */
 	FMONITOR,	/* -m: job control monitoring */
+	FNOBEEP,	/* don't beep on bell */
 	FNOCLOBBER,	/* -C: don't overwrite existing files */
 	FNOEXEC,	/* -n: don't execute any commands */
 	FNOGLOB,	/* -f: don't do file globbing */
Index: vi.c
===================================================================
RCS file: /cvs/src/bin/ksh/vi.c,v
retrieving revision 1.26
diff -p -u -r1.26 vi.c
--- vi.c	29 Jun 2009 22:50:19 -0000	1.26
+++ vi.c	26 Nov 2012 14:25:51 -0000
@@ -575,7 +575,12 @@ vi_insert(int ch)
 				es->cbuf[es->cursor] = undo->cbuf[es->cursor];
 		} else {
 			if (es->cursor == 0) {
-				/* x_putc(BEL); no annoying bell here */
+				/*
+				 * no annoying bell here
+				 *
+				if (!Flag(FNOBEEP))
+					x_putc(BEL);
+				*/
 				return 0;
 			}
 			if (inslen > 0)
@@ -2105,7 +2110,8 @@ vi_error(void)
 {
 	/* Beem out of any macros as soon as an error occurs */
 	vi_macro_reset();
-	x_putc(BEL);
+	if (!Flag(FNOBEEP))
+		x_putc(BEL);
 	x_flush();
 }
 
Index: ksh.1
===================================================================
RCS file: /cvs/src/bin/ksh/ksh.1,v
retrieving revision 1.144
diff -p -u -r1.144 ksh.1
--- ksh.1	8 Jul 2012 08:13:20 -0000	1.144
+++ ksh.1	26 Nov 2012 19:44:32 -0000
@@ -3705,6 +3704,8 @@ See above for a description of what this
 The shell is a login shell.
 This option can only be used when the shell is invoked.
 See above for a description of what this means.
+.It Ic nobeep
+Do not beep on bell.
 .It Ic nohup
 Do not kill running jobs with a
 .Dv SIGHUP