nshlib/nsh_parse: Fix "e" flag not take effect
The NSH exits when a command exits with a non-zero status, even if the "e" flag is not set.
This error does not exist in NSH scripts.
Without this patch:
nsh> sh -c "set -e; mkdir /test; echo $?"
nsh: /test: mkdir failed: 17
nsh> sh -c "set +e; mkdir /test; echo $?"
nsh: /test: mkdir failed: 17
nsh> rm /test
nsh> sh -c "set +e; mkdir /test; echo $?"
0
With this patch:
nsh> sh -c "set -e; mkdir /test; echo $?"
nsh: /test: mkdir failed: 17
nsh> sh -c "set +e; mkdir /test; echo $?"
nsh: /test: mkdir failed: 17
1
nsh> rm /test
nsh> sh -c "set +e; mkdir /test; echo $?"
0
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index ab5d390..9b7b371 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -2936,7 +2936,11 @@
/* Parse this command */
ret = nsh_parse_command(vtbl, start);
- if (ret != OK)
+ if (ret != OK
+#ifndef CONFIG_NSH_DISABLESCRIPT
+ && !(vtbl->np.np_flags & NSH_PFLAG_IGNORE)
+#endif
+ )
{
/* nsh_parse_command may return (1) -1 (ERROR) meaning that the
* command failed or we failed to start the command application