blob: 5b018d9349abfad4aece07df1f97ccbe2c39c678 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Tysereabe6d92009-10-16 17:36:25 -05002/*
3 * Copyright 2000-2009
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Peter Tysereabe6d92009-10-16 17:36:25 -05005 */
6
7#include <common.h>
8#include <command.h>
9
Kim Phillipsdc00a682012-10-29 13:34:31 +000010static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Peter Tysereabe6d92009-10-16 17:36:25 -050011{
12 int i;
13 int putnl = 1;
14
15 for (i = 1; i < argc; i++) {
Joe Hershberger55946772012-10-03 13:09:15 +000016 char *p = argv[i];
17 char *nls; /* new-line suppression */
Peter Tysereabe6d92009-10-16 17:36:25 -050018
19 if (i > 1)
20 putc(' ');
Joe Hershberger55946772012-10-03 13:09:15 +000021
22 nls = strstr(p, "\\c");
23 if (nls) {
24 char *prenls = p;
25
26 putnl = 0;
27 /*
28 * be paranoid and guess that someone might
29 * say \c more than once
30 */
31 while (nls) {
32 *nls = '\0';
33 puts(prenls);
34 *nls = '\\';
35 prenls = nls + 2;
36 nls = strstr(prenls, "\\c");
Peter Tysereabe6d92009-10-16 17:36:25 -050037 }
Joe Hershberger55946772012-10-03 13:09:15 +000038 puts(prenls);
39 } else {
40 puts(p);
Peter Tysereabe6d92009-10-16 17:36:25 -050041 }
42 }
43
44 if (putnl)
45 putc('\n');
46
47 return 0;
48}
49
50U_BOOT_CMD(
51 echo, CONFIG_SYS_MAXARGS, 1, do_echo,
52 "echo args to console",
53 "[args..]\n"
54 " - echo args to console; \\c suppresses newline"
55);