1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
http://bugs.gentoo.org/337329
http://bugs.gentoo.org/527848
http://bugs.gentoo.org/590696
There's no requirement for `echo` to support escape sequences on systems
which are not XSI compliant (like embedded systems) according to POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
This behavior breaks historical scripts, espcially if also the (not required
by POSIX) `echo -n` and `echo -e` are unsupported, in particular all scripts
generated by autoconf-2.13 will break.
Modern scripts better should avoid all these pitfalls and should always prefer
`printf` when they want anything like `echo -n` or interpretation of escape
sequences. So it might be useful to intentionally break scripts which rely on
these features. Note that this patch makes `echo` in dash behave differently
from any other existing shell.
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -442,21 +442,12 @@
int
echocmd(int argc, char **argv)
{
- int nonl;
-
- nonl = *++argv ? equal(*argv, "-n") : 0;
- argv += nonl;
-
- do {
- int c;
-
- if (likely(*argv))
- nonl += print_escape_str("%s", NULL, NULL, *argv++);
- if (nonl > 0)
- break;
-
- c = *argv ? ' ' : '\n';
- out1c(c);
- } while (*argv);
+ int i;
+ for (i = 1; i < argc; ++i) {
+ outstr(argv[i], out1);
+ if (i < argc - 1)
+ outc(' ', out1);
+ }
+ outc('\n', out1);
return 0;
}
--- a/src/dash.1
+++ b/src/dash.1
@@ -1182,43 +1182,18 @@
option turns off the effect of any preceding
.Fl P
options.
-.It Xo echo Op Fl n
+.It Xo echo
.Ar args...
.Xc
Print the arguments on the standard output, separated by spaces.
-Unless the
-.Fl n
-option is present, a newline is output following the arguments.
-.Pp
-If any of the following sequences of characters is encountered during
-output, the sequence is not output. Instead, the specified action is
-performed:
-.Bl -tag -width indent
-.It Li \eb
-A backspace character is output.
-.It Li \ec
-Subsequent output is suppressed. This is normally used at the end of the
-last argument to suppress the trailing newline that
-.Ic echo
-would otherwise output.
-.It Li \ef
-Output a form feed.
-.It Li \en
-Output a newline character.
-.It Li \er
-Output a carriage return.
-.It Li \et
-Output a (horizontal) tab character.
-.It Li \ev
-Output a vertical tab.
-.It Li \e0 Ns Ar digits
-Output the character whose value is given by zero to three octal digits.
-If there are zero digits, a nul character is output.
-.It Li \e\e
-Output a backslash.
-.El
.Pp
-All other backslash sequences elicit undefined behaviour.
+In this crippled version of dash no backslash sequences are supported.
+They will be printed out exactly as passed in.
+Also the option -n is not supported in this crippled version of dash.
+.Pp
+Moderns scripts might want to replace `echo -n ...` with the `printf %s ...`
+construct, and similarly use `printf` to for escape sequences. This is POSIX
+compliant though not compatible since some historical systems lack `printf`.
.It eval Ar string ...
Concatenate all the arguments with spaces.
Then re-parse and execute the command.
|