Skip site navigation (1)Skip section navigation (2)
Date:      24 Aug 1999 16:33:34 +0200
From:      Thomas Gellekum <tg@ihf.rwth-aachen.de>
To:        chris@calldei.com
Cc:        Sheldon Hearn <sheldonh@uunet.co.za>, Chris Piazza <cpiazza@home.net>, freebsd-bugs@FreeBSD.ORG
Subject:   Re: bin/13274: /bin/sh 'read' command does not work correctly
Message-ID:  <kqogfxz1s1.fsf@zabagek.ihf.rwth-aachen.de>
In-Reply-To: Chris Costello's message of "Tue, 24 Aug 1999 09:21:21 -0500"
References:  <67252.935481572@axl.noc.iafrica.com> <kqzozhzjnn.fsf@zabagek.ihf.rwth-aachen.de> <19990824092120.H90868@holly.dyndns.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Chris Costello <chris@calldei.com> writes:

> On Tue, Aug 24, 1999, Thomas Gellekum wrote:
> > No. This should be flagged in the manpage, IMHO.
> 
>    Please leave -e in read and do nothing in the getopt switch
> for 'e'.

See below.

tg

Index: miscbltin.c
===================================================================
RCS file: /home/ncvs/src/bin/sh/miscbltin.c,v
retrieving revision 1.18.2.1
diff -u -r1.18.2.1 miscbltin.c
--- miscbltin.c	1999/05/08 10:43:02	1.18.2.1
+++ miscbltin.c	1999/08/24 08:37:14
@@ -71,8 +71,8 @@
 
 
 /*
- * The read builtin.  The -e option causes backslashes to escape the
- * following character.
+ * The read builtin.  The -r option causes backslashes to be treated like
+ * ordinary characters.
  *
  * This uses unbuffered input, which may be avoidable in some cases.
  */
@@ -85,7 +85,7 @@
 	char **ap;
 	int backslash;
 	char c;
-	int eflag;
+	char rflag;
 	char *prompt;
 	char *ifs;
 	char *p;
@@ -98,18 +98,20 @@
 	struct termios told, tnew;
 	int tsaved;
 
-	eflag = 0;
+	rflag = 0;
 	prompt = NULL;
 	tv.tv_sec = -1;
 	tv.tv_usec = 0;
-	while ((i = nextopt("ep:t:")) != '\0') {
+	while ((i = nextopt("erp:t:")) != '\0') {
 		switch(i) {
 		case 'p':
 			prompt = optarg;
 			break;
 		case 'e':
-			eflag = 1;
 			break;
+		case 'r':
+			rflag = 1;
+			break;
 		case 't':
 			tv.tv_sec = strtol(optarg, &tvptr, 0);
 			if (tvptr == optarg)
@@ -184,7 +186,7 @@
 				STPUTC(c, p);
 			continue;
 		}
-		if (eflag && c == '\\') {
+		if (!rflag && c == '\\') {
 			backslash++;
 			continue;
 		}
Index: sh.1
===================================================================
RCS file: /home/ncvs/src/bin/sh/sh.1,v
retrieving revision 1.23.2.2
diff -u -r1.23.2.2 sh.1
--- sh.1	1999/04/19 18:54:06	1.23.2.2
+++ sh.1	1999/08/24 08:37:29
@@ -1150,7 +1150,7 @@
 it faster.  However, if the current directory is
 renamed, the builtin version of pwd will continue to
 print the old name for the directory.
-.It Li "read [ -p prompt ] [ -t timeout ] [ -e ] variable ...
+.It Li "read [ -p prompt ] [ -t timeout ] [ -e ] [ -r] variable ...
 The prompt is printed if the -p option is specified
 and the standard input is a terminal.  Then a line is
 read from the standard input.  The trailing newline
@@ -1161,7 +1161,9 @@
 pieces (along with the characters in IFS that
 separated them) are assigned to the last variable.
 If there are more variables than pieces, the remaining
-variables are assigned the null string.
+variables are assigned the null string.  A backslash at the 
+end of a line will be deleted from the input together with the
+newline character.
 .Pp
 If the -t option is specified the timeout elapses
 before any input is supplied, the read command will
@@ -1170,13 +1172,10 @@
 explicitly specify seconds, minutes or or hours.  If none
 is supplied, 's' is assumed.
 .Pp
-The -e option causes any backslashes in the input to
-be treated specially.  If a backslash is followed by
-a newline, the backslash and the newline will be
-deleted.   If a backslash is followed by any other
-character, the backslash will be deleted and the following
-character will be treated as though it were
-not in IFS, even if it is.
+The -e option is deprecated and only here for backward compatibility.
+.Pp
+The -r option causes backslashes in the input to be treated
+like ordinary characters.
 .It readonly name ...
 The specified names are marked as read only, so that
 they cannot be subsequently modified or unset.  The shell


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?kqogfxz1s1.fsf>