xiaoxiang781216 commented on code in PR #1870:
URL: https://github.com/apache/nuttx-apps/pull/1870#discussion_r1278803042
##########
nshlib/nsh_envcmds.c:
##########
@@ -300,49 +300,69 @@ int cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
{
int newline = 1;
int escape = 0;
- int opt;
- int i;
- while ((opt = getopt(argc, argv, "neE")) != ERROR)
+ --argc;
+ ++argv;
+
+ while (argc > 0 && argv[0][0] == '-')
{
- switch (opt)
+ FAR char const *temp = argv[0] + 1;
+ size_t i;
+
+ for (i = 0; temp[i]; i++)
{
- case 'n':
- newline = 0;
- break;
-
- case 'e':
- escape = 1;
- break;
-
- case 'E':
- escape = 0;
- break;
-
- case '?':
- default:
- nsh_error(vtbl, g_fmtarginvalid, argv[0]);
- return ERROR;
+ switch (temp[i])
+ {
+ case 'e':
+ case 'E':
+ case 'n':
+ break;
+ default:
+ goto do_echo;
+ }
}
- }
- /* echo each argument, separated by a space as it must have been on the
- * command line.
- */
+ if (i == 0)
+ goto do_echo;
Review Comment:
add {}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]