summaryrefslogtreecommitdiff
path: root/cmd/echo.c
blob: fda844ee9d3524ebeac6d60769cbefa3c7649e52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2000-2009
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 */

#include <common.h>
#include <command.h>

static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc,
		   char *const argv[])
{
	int i = 1;
	bool space = false;
	bool newline = true;

	if (argc > 1) {
		if (!strcmp(argv[1], "-n")) {
			newline = false;
			++i;
		}
	}

	for (; i < argc; ++i) {
		if (space) {
			putc(' ');
		}
		puts(argv[i]);
		space = true;
	}

	if (newline)
		putc('\n');

	return 0;
}

U_BOOT_CMD(
	echo, CONFIG_SYS_MAXARGS, 1, do_echo,
	"echo args to console",
	"[-n] [args..]\n"
	"    - echo args to console; -n suppresses newline"
);