This is an automated email from the ASF dual-hosted git repository.
xiaoxiang 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 6f8506201 nshlib/nsh_parse: support use \" and \' to pass " and ' to
arguments
6f8506201 is described below
commit 6f85062019c26f52c0d78d5a462789e48d28ccd8
Author: Bowen Wang <[email protected]>
AuthorDate: Thu Jul 18 14:17:14 2024 +0800
nshlib/nsh_parse: support use \" and \' to pass " and ' to arguments
Now we can pass symbol " and ' to the nsh command arguments
Signed-off-by: Bowen Wang <[email protected]>
---
nshlib/nsh_parse.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index d0973ec55..2c716946f 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -2970,28 +2970,41 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, FAR char
*cmdline)
else /* if (*ptr == '"' || *ptr == '\'') */
{
- /* Find the closing quotation mark */
+ FAR char *prev = ptr - 1;
- FAR char *tmp = nsh_strchr(ptr + 1, *ptr);
- if (!tmp)
+ if (prev >= start && *prev == '\\')
{
- /* No closing quotation mark! */
+ /* Support \" and \' in command line */
+
+ working++;
+ }
+ else
+ {
+ /* Find the closing quotation mark */
+
+ FAR char *tmp = nsh_strchr(ptr + 1, *ptr);
+ if (!tmp)
+ {
+ /* No closing quotation mark! */
#ifndef CONFIG_NSH_DISABLE_ERROR_PRINT
- char qterm[2];
+ char qterm[2];
- qterm[0] = *ptr;
- qterm[1] = '\0';
+ qterm[0] = *ptr;
+ qterm[1] = '\0';
- nsh_error(vtbl, g_fmtnomatching, qterm, qterm);
+ nsh_error(vtbl, g_fmtnomatching, qterm, qterm);
#endif
- return ERROR;
- }
+ return ERROR;
+ }
- /* Otherwise, continue parsing after the closing quotation mark */
+ /* Otherwise, continue parsing after the closing quotation
+ * mark
+ */
- working = ++tmp;
+ working = ++tmp;
+ }
}
}