1 /* echo.c, taken from Bash.
2 Copyright (C) 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GNU Bash, the Bourne Again SHell.
6 Bash is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License along
17 with Bash; see the file COPYING. If not, write to the Free Software
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #if defined (CONFIG_BROKETS)
22 /* We use <config.h> instead of "config.h" so that a compilation
23 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
24 (which it would do because it found this file in $srcdir). */
32 #include <sys/types.h>
34 #include "long-options.h"
36 /* echo [-neE] [arg ...]
37 Output the ARGs. If -n is specified, the trailing newline is
38 suppressed. If the -e option is given, interpretation of the
39 following backslash-escaped characters is turned on:
42 \c suppress trailing newline
49 \num the character whose ASCII code is NUM (octal).
51 You can explicitly turn off the interpretation of the above characters
52 on System V systems with the -E option.
55 /* If defined, interpret backslash escapes if -e is given. */
58 /* If defined, interpret backslash escapes unless -E is given.
59 V9_ECHO must also be defined. */
63 # if defined (V9_DEFAULT)
64 # define VALID_ECHO_OPTIONS "neE"
66 # define VALID_ECHO_OPTIONS "ne"
67 # endif /* !V9_DEFAULT */
69 # define VALID_ECHO_OPTIONS "n"
72 /* The name this program was run with. */
79 fprintf (status == 0 ? stdout : stderr, "\
80 Usage: %s [OPTION]... [STRING]...\n\
85 fprintf (stderr, "Try `%s --help' for more information.\n",
91 -n do not output the trailing newline\n\
93 -E disable interpolation of some sequences in STRINGs\n\
94 --help display this help and exit (should be alone)\n\
95 --version output version information and exit (should be alone)\n\
97 Without -E, the following sequences are recognized and interpolated:\n\
99 \\NNN the character whose ASCII code is NNN (octal)\n\
103 \\c suppress trailing newline\n\
106 \\r carriage return\n\
107 \\t horizontal tab\n\
114 /* Print the words in LIST to standard output. If the first word is
115 `-n', then don't print a trailing newline. We also support the
116 echo syntax from Version 9 unix systems. */
122 int display_return = 1, do_v9 = 0;
124 program_name = argv[0];
126 parse_long_options (argc, argv, usage);
128 /* System V machines already have a /bin/sh with a v9 behaviour. We
129 use the identical behaviour for these machines so that the
130 existing system shell scripts won't barf. */
131 #if defined (V9_ECHO) && defined (V9_DEFAULT)
138 while (argc > 0 && *argv[0] == '-')
143 /* If it appears that we are handling options, then make sure that
144 all of the options specified are actually valid. Otherwise, the
145 string should just be echoed. */
148 for (i = 0; temp[i]; i++)
150 if (rindex (VALID_ECHO_OPTIONS, temp[i]) == 0)
157 /* All of the options in TEMP are valid options to ECHO.
163 #if defined (V9_ECHO)
164 else if (*temp == 'e')
166 #if defined (V9_DEFAULT)
167 else if (*temp == 'E')
169 #endif /* V9_DEFAULT */
184 #if defined (V9_ECHO)
189 register char *s = argv[0];
198 case 'a': c = '\007'; break;
199 case 'b': c = '\b'; break;
200 case 'c': display_return = 0; continue;
201 case 'f': c = '\f'; break;
202 case 'n': c = '\n'; break;
203 case 'r': c = '\r'; break;
204 case 't': c = '\t'; break;
205 case 'v': c = (int) 0x0B; break;
206 case '0': case '1': case '2': case '3':
207 case '4': case '5': case '6': case '7':
209 if (*s >= '0' && *s <= '7')
210 c = c * 8 + (*s++ - '0');
211 if (*s >= '0' && *s <= '7')
212 c = c * 8 + (*s++ - '0');
215 default: putchar ('\\'); break;
231 fputs (argv[0], stdout);