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.
25 #if defined (HAVE_UNISTD_H)
29 #include "../bashansi.h"
35 $FUNCTION echo_builtin
37 $SHORT_DOC echo [-neE] [arg ...]
38 Output the ARGs. If -n is specified, the trailing newline is
39 suppressed. If the -e option is given, interpretation of the
40 following backslash-escaped characters is turned on:
43 \c suppress trailing newline
51 \num the character whose ASCII code is NUM (octal).
53 You can explicitly turn off the interpretation of the above characters
58 $FUNCTION echo_builtin
60 $SHORT_DOC echo [-n] [arg ...]
61 Output the ARGs. If -n is specified, the trailing newline is suppressed.
65 # define VALID_ECHO_OPTIONS "neE"
67 # define VALID_ECHO_OPTIONS "n"
70 /* Print the words in LIST to standard output. If the first word is
71 `-n', then don't print a trailing newline. We also support the
72 echo syntax from Version 9 Unix systems. */
77 int display_return, do_v9, i, len;
80 #if defined (DEFAULT_ECHO_TO_USG)
81 /* System V machines already have a /bin/sh with a v9 behaviour. We
82 give Bash the identical behaviour for these machines so that the
83 existing system shells won't barf. */
87 #endif /* DEFAULT_ECHO_TO_USG */
91 for (; list && (temp = list->word->word) && *temp == '-'; list = list->next)
93 /* If it appears that we are handling options, then make sure that
94 all of the options specified are actually valid. Otherwise, the
95 string should just be echoed. */
98 for (i = 0; temp[i]; i++)
100 if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0)
104 /* echo - and echo -<nonopt> both mean to just echo the arguments. */
105 if (*temp == 0 || temp[i])
108 /* All of the options in TEMP are valid options to ECHO.
117 #if defined (V9_ECHO)
126 goto just_echo; /* XXX */
136 temp = do_v9 ? ansicstr (list->word->word, STRLEN (list->word->word), &i, &len)
142 for (s = temp; len > 0; len--)
148 fflush (stdout); /* Fix for bug in SunOS 5.5 printf(3) */
166 return (EXECUTION_SUCCESS);