apps/nshlib: Add support for '-n' option to the echo command.

This commit is contained in:
Masayuki Ishikawa 2018-01-10 07:23:28 -06:00 committed by Gregory Nutt
parent f8d683c590
commit 8ecf618a4d
3 changed files with 24 additions and 23 deletions

View File

@ -466,11 +466,13 @@ o dirname <path>
Extract the path string leading up to the full <path> by removing
the final directory or file name.
o echo [<string|$name> [<string|$name>...]]
o echo [-n] [<string|$name> [<string|$name>...]]
Copy the sequence of strings and expanded environment variables to
console out (or to a file if the output is re-directed).
The -n option will suppress the trailing newline character.
o exec <hex-address>
Execute the user logic at address <hex-address>. NSH will pause

View File

@ -186,9 +186,9 @@ static const struct cmdmap_s g_cmdmap[] =
#ifndef CONFIG_NSH_DISABLE_ECHO
# ifndef CONFIG_DISABLE_ENVIRON
{ "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, "[<string|$name> [<string|$name>...]]" },
{ "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, "[-n] [<string|$name> [<string|$name>...]]" },
# else
{ "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, "[<string> [<string>...]]" },
{ "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, "[-n] [<string> [<string>...]]" },
# endif
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* apps/nshlib/nsh_envcmds.c
*
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2011-2012, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -50,18 +50,6 @@
#include "nsh.h"
#include "nsh_console.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
@ -72,10 +60,6 @@ static const char g_oldpwd[] = "OLDPWD";
static const char g_home[] = CONFIG_LIB_HOMEDIR;
#endif
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
@ -278,17 +262,32 @@ int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
int i;
int s = 1;
if (0 == strncmp(argv[1], "-n", 2))
{
s = 2;
}
/* echo each argument, separated by a space as it must have been on the
* command line
*/
for (i = 1; i < argc; i++)
for (i = s; i < argc; i++)
{
nsh_output(vtbl, "%s ", argv[i]);
if (i != s)
{
nsh_output(vtbl, " ");
}
nsh_output(vtbl, "%s", argv[i]);
}
if (1 == s)
{
nsh_output(vtbl, "\n");
}
nsh_output(vtbl, "\n");
return OK;
}
#endif