summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/ChangeLog.txt5
-rw-r--r--apps/nshlib/nsh_parse.c14
-rw-r--r--nuttx/Documentation/NuttShell.html33
3 files changed, 33 insertions, 19 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index dfb45293e..fb3bf2979 100644
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -792,3 +792,8 @@
support for while-do-done and until-do-done loops. These only work
when executing a script file because they depend on the ability to seek
in the file to implement the looping behaviors (2014-1-17).
+ * apps/nshlib/nsh_parse.c: Loosen up if-then-else-fi syntax to allow
+ a command to be on the same line as the then and else tokens like:
+ "if true; then echo true; else echo false; fi". Much more like bash!
+ (2014-1-17).
+
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index a612e892a..c7505f34d 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -1684,14 +1684,9 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
else if (strcmp(cmd, "then") == 0)
{
- /* Get the cmd following the "then" -- there shouldn't be one */
+ /* Get the cmd following the "then" -- there may or may not be one */
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
- if (*ppcmd)
- {
- nsh_output(vtbl, g_fmtarginvalid, "then");
- goto errout;
- }
/* Verify that "then" is valid in this context */
@@ -1708,14 +1703,9 @@ static int nsh_itef(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd,
else if (strcmp(cmd, "else") == 0)
{
- /* Get the cmd following the "else" -- there shouldn't be one */
+ /* Get the cmd following the "else" -- there may or may not be one */
*ppcmd = nsh_argument(vtbl, saveptr, memlist);
- if (*ppcmd)
- {
- nsh_output(vtbl, g_fmtarginvalid, "else");
- goto errout;
- }
/* Verify that "else" is valid in this context */
diff --git a/nuttx/Documentation/NuttShell.html b/nuttx/Documentation/NuttShell.html
index 603ae759d..2eeed4e67 100644
--- a/nuttx/Documentation/NuttShell.html
+++ b/nuttx/Documentation/NuttShell.html
@@ -618,15 +618,34 @@ fi
<p>
<code>while-do-done</code> and <code>until-do-done</code> looping constructs are also supported.
- These works from the command line but are primarily intended for use within NSH scripts
+ These work from the command line but are primarily intended for use within NSH scripts
(see the <a href="#cmdsh"><code>sh</code></a> command).
- The syntax is as follows:
</p>
-<ul><dl>
- <dt><code>while &lt;test-cmd&gt;; do &lt;cmd-sequence&gt;; done</code></dt>
- <dd>Execute <code>&lt;cmd-sequence&gt;</code> as long as <code>&lt;test-cmd&gt;</code> has an exit status of zero.</dd>
- <dt><code>until &lt;test-cmd&gt;; do &lt;cmd-sequence&gt;; done</code></dt>
- <dd>Execute <code>&lt;cmd-sequence&gt;</code> as long as <code>&lt;test-cmd&gt;</code> has a non-zero exit status.</dd>
+<ul>
+ <li>
+ <p><b><code>while-do-done</code></b>.
+ Execute <code>[sequence of &lt;cmd&gt;]</code> as long as <code>&lt;cmd&gt;</code> has an exit status of zero.
+ The syntax is as follows:
+ <ul><pre>
+while &lt;cmd&gt;
+do
+ [sequence of &lt;cmd&gt;]
+done
+</pre></ul>
+ </p>
+ </li>
+ <li>
+ <p><b><code>until-do-done</code></b>
+ Execute <code>[sequence of &lt;cmd&gt;]</code> as long as <code>&lt;cmd&gt;</code> has a non-zero exit status.
+ The syntax is as follows:
+ <ul><pre>
+while &lt;cmd&gt;
+do
+ [sequence of &lt;cmd&gt;]
+done
+</pre></ul>
+ </p>
+ </li>
</dl></ul>
<table width ="100%">