Per 1003.2, the (builtin) read utility shall treat the backslash as an

escape character (including line continuation), unless the `-r' option
is specified:
* adopt to this behaviour, add the `-r' option to disable it;
* remove the `-e' option, which was previously necessary to get this behaviour.
This commit is contained in:
kleink 1997-11-05 14:05:28 +00:00
parent ad5a9cf050
commit 3780e6aa5d
2 changed files with 14 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: miscbltin.c,v 1.19 1997/07/04 21:02:09 christos Exp $ */ /* $NetBSD: miscbltin.c,v 1.20 1997/11/05 14:05:28 kleink Exp $ */
/*- /*-
* Copyright (c) 1991, 1993 * Copyright (c) 1991, 1993
@ -41,7 +41,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95";
#else #else
__RCSID("$NetBSD: miscbltin.c,v 1.19 1997/07/04 21:02:09 christos Exp $"); __RCSID("$NetBSD: miscbltin.c,v 1.20 1997/11/05 14:05:28 kleink Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -66,7 +66,7 @@ __RCSID("$NetBSD: miscbltin.c,v 1.19 1997/07/04 21:02:09 christos Exp $");
#include "miscbltin.h" #include "miscbltin.h"
#include "mystring.h" #include "mystring.h"
#undef eflag #undef rflag
extern char **argptr; /* argument list for builtin command */ extern char **argptr; /* argument list for builtin command */
@ -86,7 +86,7 @@ readcmd(argc, argv)
char **ap; char **ap;
int backslash; int backslash;
char c; char c;
int eflag; int rflag;
char *prompt; char *prompt;
char *ifs; char *ifs;
char *p; char *p;
@ -94,13 +94,13 @@ readcmd(argc, argv)
int status; int status;
int i; int i;
eflag = 0; rflag = 0;
prompt = NULL; prompt = NULL;
while ((i = nextopt("ep:")) != '\0') { while ((i = nextopt("p:r")) != '\0') {
if (i == 'p') if (i == 'p')
prompt = optarg; prompt = optarg;
else else
eflag = 1; rflag = 1;
} }
if (prompt && isatty(0)) { if (prompt && isatty(0)) {
out2str(prompt); out2str(prompt);
@ -127,7 +127,7 @@ readcmd(argc, argv)
STPUTC(c, p); STPUTC(c, p);
continue; continue;
} }
if (eflag && c == '\\') { if (!rflag && c == '\\') {
backslash++; backslash++;
continue; continue;
} }

View File

@ -1,4 +1,4 @@
.\" $NetBSD: sh.1,v 1.21 1997/07/10 23:07:04 phil Exp $ .\" $NetBSD: sh.1,v 1.22 1997/11/05 14:05:31 kleink Exp $
.\" Copyright (c) 1991, 1993 .\" Copyright (c) 1991, 1993
.\" The Regents of the University of California. All rights reserved. .\" The Regents of the University of California. All rights reserved.
.\" .\"
@ -1263,7 +1263,7 @@ it faster. However, if the current directory is
renamed, the builtin version of pwd will continue to renamed, the builtin version of pwd will continue to
print the old name for the directory. print the old name for the directory.
.TP .TP
read [ -p prompt ] [ -e ] variable... read [ -p prompt ] [ -r ] variable...
The prompt is printed if the -p option is specified The prompt is printed if the -p option is specified
and the standard input is a terminal. Then a line is and the standard input is a terminal. Then a line is
read from the standard input. The trailing newline read from the standard input. The trailing newline
@ -1276,13 +1276,10 @@ separated them) are assigned to the last variable.
If there are more variables than pieces, the remaining If there are more variables than pieces, the remaining
variables are assigned the null string. variables are assigned the null string.
.sp .sp
The -e option causes any backslashes in the input to By default, unless the -r option is specified, the backslash
be treated specially. If a backslash is followed by (\\) acts as an escape character, causing the following
a newline, the backslash and the newline will be character to be treated literally. If a backslash is followed
deleted. If a backslash is followed by any other by a newline, the backslash and the newline will be deleted.
character, the backslash will be deleted and the following
character will be treated as though it were
not in IFS, even if it is.
.TP .TP
readonly name... readonly name...
The specified names are marked as read only, so that The specified names are marked as read only, so that