blob: 973213a03a66b57af5172e470a095b0e94f58e51 [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
Peter Tysereabe6d92009-10-16 17:36:25 -05007#include <command.h>
8
Simon Glassed38aef2020-05-10 11:40:03 -06009static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc,
10 char *const argv[])
Peter Tysereabe6d92009-10-16 17:36:25 -050011{
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010012 int i = 1;
13 bool space = false;
14 bool newline = true;
Peter Tysereabe6d92009-10-16 17:36:25 -050015
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010016 if (argc > 1) {
17 if (!strcmp(argv[1], "-n")) {
18 newline = false;
19 ++i;
20 }
21 }
Peter Tysereabe6d92009-10-16 17:36:25 -050022
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010023 for (; i < argc; ++i) {
24 if (space) {
Peter Tysereabe6d92009-10-16 17:36:25 -050025 putc(' ');
Peter Tysereabe6d92009-10-16 17:36:25 -050026 }
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010027 puts(argv[i]);
28 space = true;
Peter Tysereabe6d92009-10-16 17:36:25 -050029 }
30
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010031 if (newline)
Peter Tysereabe6d92009-10-16 17:36:25 -050032 putc('\n');
33
34 return 0;
35}
36
37U_BOOT_CMD(
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010038 echo, CONFIG_SYS_MAXARGS, 1, do_echo,
Peter Tysereabe6d92009-10-16 17:36:25 -050039 "echo args to console",
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010040 "[-n] [args..]\n"
41 " - echo args to console; -n suppresses newline"
Peter Tysereabe6d92009-10-16 17:36:25 -050042);