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

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


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

commit 2bd806a9b20831f208f242109ce4d14b4692c6f2
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