diff --git a/nshlib/README.txt b/nshlib/README.txt index afa6285ec..1dcd760b7 100644 --- a/nshlib/README.txt +++ b/nshlib/README.txt @@ -466,11 +466,13 @@ o dirname Extract the path string leading up to the full by removing the final directory or file name. -o echo [ [...]] +o echo [-n] [ [...]] 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 Execute the user logic at address . NSH will pause diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index f9d3ac559..d9c6ae3c6 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -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, "[ [...]]" }, + { "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, "[-n] [ [...]]" }, # else - { "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, "[ [...]]" }, + { "echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS, "[-n] [ [...]]" }, # endif #endif diff --git a/nshlib/nsh_envcmds.c b/nshlib/nsh_envcmds.c index 4d80e465c..6839a452c 100644 --- a/nshlib/nsh_envcmds.c +++ b/nshlib/nsh_envcmds.c @@ -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 * * 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