blob: fda844ee9d3524ebeac6d60769cbefa3c7649e52 [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
Simon Glassed38aef2020-05-10 11:40:03 -060010static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc,
11 char *const argv[])
Peter Tysereabe6d92009-10-16 17:36:25 -050012{
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010013 int i = 1;
14 bool space = false;
15 bool newline = true;
Peter Tysereabe6d92009-10-16 17:36:25 -050016
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010017 if (argc > 1) {
18 if (!strcmp(argv[1], "-n")) {
19 newline = false;
20 ++i;
21 }
22 }
Peter Tysereabe6d92009-10-16 17:36:25 -050023
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010024 for (; i < argc; ++i) {
25 if (space) {
Peter Tysereabe6d92009-10-16 17:36:25 -050026 putc(' ');
Peter Tysereabe6d92009-10-16 17:36:25 -050027 }
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010028 puts(argv[i]);
29 space = true;
Peter Tysereabe6d92009-10-16 17:36:25 -050030 }
31
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010032 if (newline)
Peter Tysereabe6d92009-10-16 17:36:25 -050033 putc('\n');
34
35 return 0;
36}
37
38U_BOOT_CMD(
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010039 echo, CONFIG_SYS_MAXARGS, 1, do_echo,
Peter Tysereabe6d92009-10-16 17:36:25 -050040 "echo args to console",
Heinrich Schuchardta2f472d2021-01-20 12:13:30 +010041 "[-n] [args..]\n"
42 " - echo args to console; -n suppresses newline"
Peter Tysereabe6d92009-10-16 17:36:25 -050043);