This is an automated email from the ASF dual-hosted git repository.

michallenc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new ae718ba47 nsh/echo: Fix echo previous behavior, single write with '\n'
ae718ba47 is described below

commit ae718ba47fd396d649939c1f54f09b92e096a594
Author: Alan Carvalho de Assis <[email protected]>
AuthorDate: Fri Jun 26 12:41:02 2026 -0300

    nsh/echo: Fix echo previous behavior, single write with '\n'
    
    This commit fixes the previous behavior where an echo with a
    single string and its default new line is send as single write().
    
    This issue came from:  https://github.com/apache/nuttx-apps/pull/1559
    
    Signed-off-by: Alan C. Assis <[email protected]>
---
 nshlib/nsh_envcmds.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/nshlib/nsh_envcmds.c b/nshlib/nsh_envcmds.c
index 442d6b2ba..52be0e96c 100644
--- a/nshlib/nsh_envcmds.c
+++ b/nshlib/nsh_envcmds.c
@@ -390,19 +390,18 @@ do_echo:
           str_escape(argv[0]);
         }
 
-      nsh_output(vtbl, "%s", argv[0]);
-
-      --argc;
-      ++argv;
-      if (argc > 0)
+      if (argc > 1)
         {
-          nsh_output(vtbl, " ");
+          nsh_output(vtbl, "%s ", argv[0]);
+        }
+      else
+        {
+          nsh_output(vtbl, newline ? "%s\n" : "%s", argv[0]);
+          break;
         }
-    }
 
-  if (newline)
-    {
-      nsh_output(vtbl, "\n");
+      --argc;
+      ++argv;
     }
 
   return OK;

Reply via email to