blob: 3dc3a63f6aa71a48c04156eabd86726820bcaa3f [file] [log] [blame]
Peter Tysereabe6d92009-10-16 17:36:25 -05001/*
2 * Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Peter Tysereabe6d92009-10-16 17:36:25 -05006 */
7
8#include <common.h>
9#include <command.h>
10
Kim Phillipsdc00a682012-10-29 13:34:31 +000011static int do_echo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Peter Tysereabe6d92009-10-16 17:36:25 -050012{
13 int i;
14 int putnl = 1;
15
16 for (i = 1; i < argc; i++) {
Joe Hershberger55946772012-10-03 13:09:15 +000017 char *p = argv[i];
18 char *nls; /* new-line suppression */
Peter Tysereabe6d92009-10-16 17:36:25 -050019
20 if (i > 1)
21 putc(' ');
Joe Hershberger55946772012-10-03 13:09:15 +000022
23 nls = strstr(p, "\\c");
24 if (nls) {
25 char *prenls = p;
26
27 putnl = 0;
28 /*
29 * be paranoid and guess that someone might
30 * say \c more than once
31 */
32 while (nls) {
33 *nls = '\0';
34 puts(prenls);
35 *nls = '\\';
36 prenls = nls + 2;
37 nls = strstr(prenls, "\\c");
Peter Tysereabe6d92009-10-16 17:36:25 -050038 }
Joe Hershberger55946772012-10-03 13:09:15 +000039 puts(prenls);
40 } else {
41 puts(p);
Peter Tysereabe6d92009-10-16 17:36:25 -050042 }
43 }
44
45 if (putnl)
46 putc('\n');
47
48 return 0;
49}
50
51U_BOOT_CMD(
52 echo, CONFIG_SYS_MAXARGS, 1, do_echo,
53 "echo args to console",
54 "[args..]\n"
55 " - echo args to console; \\c suppresses newline"
56);