1 This file is echo.def, from which is created echo.c.
2 It implements the builtin "echo" in Bash.
4 Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 1, or (at your option) any later
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 $FUNCTION echo_builtin
29 $SHORT_DOC echo [-neE] [arg ...]
30 Output the ARGs. If -n is specified, the trailing newline is
31 suppressed. If the -e option is given, interpretation of the
32 following backslash-escaped characters is turned on:
35 \c suppress trailing newline
42 \num the character whose ASCII code is NUM (octal).
44 You can explicitly turn off the interpretation of the above characters
49 $FUNCTION echo_builtin
51 $SHORT_DOC echo [-n] [arg ...]
52 Output the ARGs. If -n is specified, the trailing newline is suppressed.
56 # define VALID_ECHO_OPTIONS "neE"
58 # define VALID_ECHO_OPTIONS "n"
61 /* Print the words in LIST to standard output. If the first word is
62 `-n', then don't print a trailing newline. We also support the
63 echo syntax from Version 9 unix systems. */
67 int display_return = 1, do_v9 = 0;
69 #if defined (DEFAULT_ECHO_TO_USG)
70 /* System V machines already have a /bin/sh with a v9 behaviour. We
71 give Bash the identical behaviour for these machines so that the
72 existing system shells won't barf. */
74 #endif /* DEFAULT_ECHO_TO_USG */
76 while (list && list->word->word[0] == '-')
81 /* If it appears that we are handling options, then make sure that
82 all of the options specified are actually valid. Otherwise, the
83 string should just be echoed. */
84 temp = &(list->word->word[1]);
86 for (i = 0; temp[i]; i++)
88 if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0)
95 /* All of the options in TEMP are valid options to ECHO.
101 #if defined (V9_ECHO)
102 else if (*temp == 'e')
104 else if (*temp == 'E')
119 #if defined (V9_ECHO)
124 register char *s = list->word->word;
133 case 'a': c = '\007'; break;
134 case 'b': c = '\b'; break;
135 case 'c': display_return = 0; continue;
136 case 'f': c = '\f'; break;
137 case 'n': c = '\n'; break;
138 case 'r': c = '\r'; break;
139 case 't': c = '\t'; break;
140 case 'v': c = (int) 0x0B; break;
141 case '0': case '1': case '2': case '3':
142 case '4': case '5': case '6': case '7':
144 if (*s >= '0' && *s <= '7')
145 c = c * 8 + (*s++ - '0');
146 if (*s >= '0' && *s <= '7')
147 c = c * 8 + (*s++ - '0');
150 default: putchar ('\\'); break;
162 print_word_list (list, " ");
167 return (EXECUTION_SUCCESS);