Make the behaviour of `read -e', ie. treating backslashes as special,
the default. Add -r option for the read builtin to reverse this. PR: 13274 Reviewed by: cpiazza, hoek, sheldonh
This commit is contained in:
parent
945ebc8846
commit
da827dcea3
@ -39,7 +39,7 @@
|
||||
static char sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id: miscbltin.c,v 1.18 1998/12/16 04:45:35 imp Exp $";
|
||||
"$Id: miscbltin.c,v 1.19 1999/05/08 10:21:56 kris Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -71,8 +71,8 @@ extern char **argptr; /* argument list for builtin command */
|
||||
|
||||
|
||||
/*
|
||||
* 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 @@ readcmd(argc, argv)
|
||||
char **ap;
|
||||
int backslash;
|
||||
char c;
|
||||
int eflag;
|
||||
int rflag;
|
||||
char *prompt;
|
||||
char *ifs;
|
||||
char *p;
|
||||
@ -98,17 +98,19 @@ readcmd(argc, argv)
|
||||
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);
|
||||
@ -184,7 +186,7 @@ readcmd(argc, argv)
|
||||
STPUTC(c, p);
|
||||
continue;
|
||||
}
|
||||
if (eflag && c == '\\') {
|
||||
if (!rflag && c == '\\') {
|
||||
backslash++;
|
||||
continue;
|
||||
}
|
||||
|
20
bin/sh/sh.1
20
bin/sh/sh.1
@ -33,7 +33,7 @@
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
|
||||
.\" $Id: sh.1,v 1.27 1999/04/03 11:41:46 cracauer Exp $
|
||||
.\" $Id: sh.1,v 1.28 1999/04/19 18:48:26 max Exp $
|
||||
.\"
|
||||
.Dd May 5, 1995
|
||||
.Dt SH 1
|
||||
@ -1150,7 +1150,7 @@ is rather than recomputing it each time. This makes
|
||||
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 ] [ -er ] 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
|
||||
@ -1163,6 +1163,14 @@ separated them) are assigned to the last variable.
|
||||
If there are more variables than pieces, the remaining
|
||||
variables are assigned the null string.
|
||||
.Pp
|
||||
Backslashes are treated specially, unless the -r option is
|
||||
specified. 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.
|
||||
.Pp
|
||||
If the -t option is specified the timeout elapses
|
||||
before any input is supplied, the read command will
|
||||
return without assigning any values. The timeout value
|
||||
@ -1170,13 +1178,7 @@ may optionally be followed by one of 's', 'm' or 'h' to
|
||||
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 exists only for backward compatibility with older scripts.
|
||||
.It readonly name ...
|
||||
The specified names are marked as read only, so that
|
||||
they cannot be subsequently modified or unset. The shell
|
||||
|
Loading…
Reference in New Issue
Block a user