blob: 25f8431388d1dc1706a2dbad43befc0ccd7c551f [file] [log] [blame]
<!--
Documentation/_templates/layout.html
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. The
ASF licenses this file to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
-->
<!DOCTYPE html>
<html class="writer-html5" lang="en">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview &mdash; NuttX latest documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../../_static/css/theme.css" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="../../_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" />
<link rel="stylesheet" type="text/css" href="../../_static/custom.css" />
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<script src="../../_static/clipboard.min.js"></script>
<script src="../../_static/copybutton.js"></script>
<script src="../../_static/design-tabs.js"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Commands" href="commands.html" />
<link rel="prev" title="NuttShell (NSH)" href="index.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> NuttX
</a>
<!-- this version selector is quite ugly, should be probably replaced by something
more modern -->
<div class="version-selector">
<select onchange="javascript:location.href = this.value;">
<option value="../../../latest" selected="selected">latest</option>
<option value="../../../10.0.0" >10.0.0</option>
<option value="../../../10.0.1" >10.0.1</option>
<option value="../../../10.1.0" >10.1.0</option>
<option value="../../../10.2.0" >10.2.0</option>
<option value="../../../10.3.0" >10.3.0</option>
<option value="../../../11.0.0" >11.0.0</option>
<option value="../../../12.0.0" >12.0.0</option>
<option value="../../../12.1.0" >12.1.0</option>
<option value="../../../12.2.0" >12.2.0</option>
<option value="../../../12.2.1" >12.2.1</option>
<option value="../../../12.3.0" >12.3.0</option>
<option value="../../../12.4.0" >12.4.0</option>
<option value="../../../12.5.0" >12.5.0</option>
<option value="../../../12.5.1" >12.5.1</option>
<option value="../../../12.6.0" >12.6.0</option>
<option value="../../../12.7.0" >12.7.0</option>
<option value="../../../12.8.0" >12.8.0</option>
<option value="../../../12.9.0" >12.9.0</option>
<option value="../../../12.10.0" >12.10.0</option>
<option value="../../../12.11.0" >12.11.0</option>
</select>
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Table of Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contributing/index.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../platforms/index.html">Supported Platforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../components/index.html">OS Components</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">Applications</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../audioutils/index.html">Audio Utility libraries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../boot/index.html">Bootloader Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../benchmarks/index.html">Benchmark Applications</a></li>
<li class="toctree-l2"><a class="reference internal" href="../canutils/index.html">CAN Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../crypto/index.html">Cryptography Library Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../fsutils/index.html">File System Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../games/index.html">Games</a></li>
<li class="toctree-l2"><a class="reference internal" href="../graphics/index.html">Graphics Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../industry/index.html">Industrial Applications</a></li>
<li class="toctree-l2"><a class="reference internal" href="../inertial/index.html">Inertial Libraries Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../interpreters/index.html">Interpreters</a></li>
<li class="toctree-l2"><a class="reference internal" href="../logging/index.html">Logging Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../lte/index.html">LTE Libraries and NSH Add-Ons</a></li>
<li class="toctree-l2"><a class="reference internal" href="../math/index.html">Math Library Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mlearing/index.html">Machine Learning Support</a></li>
<li class="toctree-l2"><a class="reference internal" href="../netutils/index.html">Network Utilities</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">NuttShell (NSH)</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">Overview</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#console-nsh-front-end">Console/NSH Front End</a></li>
<li class="toctree-l4"><a class="reference internal" href="#command-overview">Command Overview</a></li>
<li class="toctree-l4"><a class="reference internal" href="#conditional-command-execution">Conditional Command Execution</a></li>
<li class="toctree-l4"><a class="reference internal" href="#looping">Looping</a></li>
<li class="toctree-l4"><a class="reference internal" href="#built-in-variables">Built-In Variables</a></li>
<li class="toctree-l4"><a class="reference internal" href="#current-working-directory">Current Working Directory</a></li>
<li class="toctree-l4"><a class="reference internal" href="#environment-variables">Environment Variables</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="commands.html">Commands</a></li>
<li class="toctree-l3"><a class="reference internal" href="config.html">Configuration Settings</a></li>
<li class="toctree-l3"><a class="reference internal" href="customizing.html">The NSH Library and NSH Initialization</a></li>
<li class="toctree-l3"><a class="reference internal" href="customizing.html#nsh-commands">NSH Commands</a></li>
<li class="toctree-l3"><a class="reference internal" href="builtin.html">NSH “Built-In” Applications</a></li>
<li class="toctree-l3"><a class="reference internal" href="installation.html">Customizing NSH Initialization</a></li>
<li class="toctree-l3"><a class="reference internal" href="login.html">Shell Login</a></li>
<li class="toctree-l3"><a class="reference internal" href="running_apps.html">Running Applications from NSH</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../sdr/index.html">Software Define Radio Libraries</a></li>
<li class="toctree-l2"><a class="reference internal" href="../system/index.html">System Libraries and NSH Add-Ons</a></li>
<li class="toctree-l2"><a class="reference internal" href="../testing/index.html">Testing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../tools/index.html">Host Side Tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="../wireless/index.html">Wireless Libraries and NSH Add-Ons</a></li>
<li class="toctree-l2"><a class="reference internal" href="../examples/index.html">Examples</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../implementation/index.html">Implementation Details</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../reference/index.html">API Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../debugging/index.html">Debugging</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guides/index.html">Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../logos/index.html">NuttX Logos</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../_tags/tagsindex.html">Tags</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">NuttX</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">Applications</a></li>
<li class="breadcrumb-item"><a href="index.html">NuttShell (NSH)</a></li>
<li class="breadcrumb-item active">Overview</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/apache/nuttx/blob/master/Documentation/applications/nsh/nsh.rst" class="fa fa-github"> Edit on GitHub</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="overview">
<span id="nsh"></span><h1>Overview<a class="headerlink" href="#overview" title="Permalink to this heading"></a></h1>
<p><strong>The NSH Library</strong>. The <code class="docutils literal notranslate"><span class="pre">apps/nshlib</span></code> sub-directory contains the
NuttShell (NSH) library. This library can easily to linked to
produce a NSH application (See as an example
<code class="docutils literal notranslate"><span class="pre">apps/examples/nsh</span></code>). The NSH Library provides a simple shell
application for NuttX.</p>
<section id="console-nsh-front-end">
<h2>Console/NSH Front End<a class="headerlink" href="#console-nsh-front-end" title="Permalink to this heading"></a></h2>
<p><strong>NSH Consoles</strong>. Using settings in the configuration file, NSH may be
configured to use (1) the serial stdin/out, (2) a USB serial
device (such as CDC/ACM), or (3) a telnet connection as the
console. Or, perhaps even all at once since or BOTH. An indefinite
number of telnet sessions are supported.</p>
<p><strong>Start-Up prompt</strong>. When NSH is started, you will see the a welcome
message such the following on the selected console:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>NuttShell (NSH)
nsh&gt;
</pre></div>
</div>
<p>The greeting may also include NuttX versioning information if you
are using a versioned copy of NuttX. <code class="docutils literal notranslate"><span class="pre">nsh&gt;</span></code> is the NSH prompt
and indicates that you may enter a command from the console.</p>
<p><strong>USB console startup</strong>. When using a USB console, the start-up
sequence differs a little: In this case, you are required to press
<em>ENTER</em> three times. Then NSH prompt will appear as described
above. This is required for the following reasons:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>This assures that the USB connection is stable. The USB
connection may be made, broken, and re-established a few times
if the USB cable is not yet fully seated. Waiting for <em>ENTER</em>
to be pressed three times assures that the connection is
stable.</p></li>
<li><p>The establishment of the connection is two step process: First,
the USB serial connection is made with the host PC. Then the
application that uses the serial interface is started on the
host. When the serial connection is established on the host,
the host operating system may send several <em>AT</em> modem commands
to the host depending upon how the host serial port is
configured. By waiting for <em>ENTER</em> to be pressed three
consecutive times, all of these modem commands will go to the
bit-bucket and will not be interpreted as NSH command input.</p></li>
<li><p>Similarly, in the second step when the applications is started,
there may be additional <em>AT</em> modem commands sent out the serial
port. Most serial terminal programs will do this unless they
are specifically configured to suppress the modem command
output. Waiting for the <em>ENTER</em> input eliminates the invalid
command errors from both (2) and (3).</p></li>
<li><p>Finally, if NSH did not wait for some positive indication that
the serial terminal program is up and running, then the output
of the NSH greeting and initial NSH prompt would be lost.</p></li>
</ol>
</div></blockquote>
<p><strong>Extended Command Line Editing</strong>. By default, NuttX uses a simple
command line editor that allows command entry after the <code class="docutils literal notranslate"><span class="pre">nsh&gt;</span></code>
and supports only the <em>backspace</em> key for editing. However, a more
complete command line editor can be selected by setting
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_CLE=y</span></code> in the NuttX configuration file. When that
option is selected, the following EMACS-like line editing commands
are supported:</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Key Binding</p></th>
<th class="head"><p>Editor Action</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">^A</span></code></p></td>
<td><p>Move cursor to start of the line</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">^B</span></code></p></td>
<td><p>Move left one character</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">^D</span></code> or <em>Del</em></p></td>
<td><p>Delete a single character at the cursor position</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">^E</span></code></p></td>
<td><p>Move cursor to end of current line</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">^F</span></code></p></td>
<td><p>Move right one character</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">^H</span></code> or <em>Backspace</em></p></td>
<td><p>Delete character, left (backspace)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">^K</span></code></p></td>
<td><p>Delete to the end of the line</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">^U</span></code></p></td>
<td><p>Delete the entire line</p></td>
</tr>
</tbody>
</table>
</section>
<section id="command-overview">
<h2>Command Overview<a class="headerlink" href="#command-overview" title="Permalink to this heading"></a></h2>
<p><strong>Simple, Re-directed, and Background Commands</strong>. The NuttShell
(NSH) is a simple shell application. NSH supports the following
commands forms:</p>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><p>Simple command</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>Command with re-directed output</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span> <span class="pre">&gt;</span> <span class="pre">&lt;file&gt;</span> <span class="pre">&lt;cmd&gt;</span> <span class="pre">&gt;&gt;</span> <span class="pre">&lt;file&gt;</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>Background command</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span> <span class="pre">&amp;</span></code></p></td>
</tr>
<tr class="row-even"><td><p>Re-directed background command</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span> <span class="pre">&gt;</span> <span class="pre">&lt;file&gt;</span> <span class="pre">&amp;</span> <span class="pre">&lt;cmd&gt;</span> <span class="pre">&gt;&gt;</span> <span class="pre">&lt;file&gt;</span> <span class="pre">&amp;</span></code></p></td>
</tr>
</tbody>
</table>
<p>Where:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span></code> is any one of the simple commands listed later.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">&lt;file&gt;</span></code> is the full or relative path to any writable object in the file system name space (file or character driver). Such objects will be referred to simply as files throughout this document.</p></li>
</ul>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">nice</span></code> <strong>‘d Background Commands</strong>. NSH executes at the
mid-priority (128). Backgrounded commands can be made to execute
at higher or lower priorities using <code class="docutils literal notranslate"><span class="pre">nice</span></code>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[nice [-d &lt;niceness&gt;&gt;]] &lt;cmd&gt; [&gt; &lt;file&gt;|&gt;&gt; &lt;file&gt;] [&amp;]
</pre></div>
</div>
<p>Where <code class="docutils literal notranslate"><span class="pre">&lt;niceness&gt;</span></code> is any value between -20 and 19 where lower
(more negative values) correspond to higher priorities. The
default niceness is 10.</p>
<p><strong>Multiple commands per line</strong>. NSH will accept multiple commands
per command line with each command separated with the semi-colon
character (;).</p>
<p><strong>Optional Syntax Extensions</strong> Because these features commit
significant resources, they are disabled by default.</p>
<blockquote>
<div><ul>
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_CMDPARMS</span></code>: If selected, then the output from
commands, from file applications, and from NSH built-in
commands can be used as arguments to other commands. The entity
to be executed is identified by enclosing the command line in
back quotes. For example,</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="w"> </span>FOO<span class="w"> </span><span class="sb">`</span>myprogram<span class="w"> </span><span class="nv">$BAR</span><span class="sb">`</span>
</pre></div>
</div>
<p>Will execute the program named <code class="docutils literal notranslate"><span class="pre">myprogram</span></code> passing it the
value of the environment variable <code class="docutils literal notranslate"><span class="pre">BAR</span></code>. The value of the
environment variable <code class="docutils literal notranslate"><span class="pre">FOO</span></code> is then set output of
<code class="docutils literal notranslate"><span class="pre">myprogram</span></code> on <code class="docutils literal notranslate"><span class="pre">stdout</span></code>.</p>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARGCAT</span></code>: Support concatenation of strings
with environment variables or command output. For example:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="w"> </span>FOO<span class="w"> </span>XYZ
<span class="nb">set</span><span class="w"> </span>BAR<span class="w"> </span><span class="m">123</span>
<span class="nb">set</span><span class="w"> </span>FOOBAR<span class="w"> </span>ABC_<span class="si">${</span><span class="nv">FOO</span><span class="si">}</span>_<span class="si">${</span><span class="nv">BAR</span><span class="si">}</span>
</pre></div>
</div>
<p>would set the environment variable <code class="docutils literal notranslate"><span class="pre">FOO</span></code> to <code class="docutils literal notranslate"><span class="pre">XYZ</span></code>, <code class="docutils literal notranslate"><span class="pre">BAR</span></code>
to <code class="docutils literal notranslate"><span class="pre">123</span></code> and <code class="docutils literal notranslate"><span class="pre">FOOBAR</span></code> to <code class="docutils literal notranslate"><span class="pre">ABC_XYZ_123</span></code>. If
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARGCAT</span></code> is not selected, then a slightly smaller
FLASH footprint results but then also only simple environment
variables like <code class="docutils literal notranslate"><span class="pre">$FOO</span></code> can be used on the command line.</p>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_QUOTE</span></code>: Enables back-slash quoting of certain
characters within the command. This option is useful for the
case where an NSH script is used to dynamically generate a new
NSH script. In that case, commands must be treated as simple
text strings without interpretation of any special characters.
Special characters such as <code class="docutils literal notranslate"><span class="pre">$</span></code>, <code class="docutils literal notranslate"><span class="pre">`</span></code>, <code class="docutils literal notranslate"><span class="pre">&quot;</span></code>, and
others must be retained intact as part of the test string. This
option is currently only available is <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARGCAT</span></code> is
also selected.</p></li>
</ul>
</div></blockquote>
</section>
<section id="conditional-command-execution">
<h2>Conditional Command Execution<a class="headerlink" href="#conditional-command-execution" title="Permalink to this heading"></a></h2>
<p>An <code class="docutils literal notranslate"><span class="pre">if-then[-else]-fi</span></code> construct is also supported in order to
support conditional execution of commands. This works from the
command line but is primarily intended for use within NSH scripts
(see the <code class="docutils literal notranslate"><span class="pre">`sh</span></code> &lt;#cmdsh&gt;`__ command). The syntax is as follows:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="o">[</span>!<span class="o">]</span><span class="w"> </span>&lt;cmd&gt;
<span class="k">then</span>
<span class="w"> </span><span class="o">[</span>sequence<span class="w"> </span>of<span class="w"> </span>&lt;cmd&gt;<span class="o">]</span>
<span class="k">else</span>
<span class="w"> </span><span class="o">[</span>sequence<span class="w"> </span>of<span class="w"> </span>&lt;cmd&gt;<span class="o">]</span>
<span class="k">fi</span>
</pre></div>
</div>
<p>Where <code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span></code> is a <a class="reference external" href="#command-overview">simple command</a>. The
command success value of zero is treated true; a non-zero command
failure value is treated false. The <code class="docutils literal notranslate"><span class="pre">`test</span></code> &lt;#cmdtest&gt;`__
command is frequently used for comparisons.</p>
<p>Examples:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>nsh&gt;<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nb">test</span><span class="w"> </span><span class="m">1</span><span class="w"> </span>-eq<span class="w"> </span><span class="m">1</span><span class="p">;</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;1 is equal 1&quot;</span><span class="p">;</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;1 is not equal 1&quot;</span><span class="p">;</span><span class="w"> </span><span class="k">fi</span>
<span class="m">1</span><span class="w"> </span>is<span class="w"> </span>equal<span class="w"> </span><span class="m">1</span>
nsh&gt;<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nb">test</span><span class="w"> </span><span class="m">1</span><span class="w"> </span>-eq<span class="w"> </span><span class="m">0</span><span class="p">;</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;1 is equal 0&quot;</span><span class="p">;</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;1 is not equal 0&quot;</span><span class="p">;</span><span class="w"> </span><span class="k">fi</span>
<span class="m">1</span><span class="w"> </span>is<span class="w"> </span>not<span class="w"> </span>equal<span class="w"> </span><span class="m">0</span>
</pre></div>
</div>
</section>
<section id="looping">
<h2>Looping<a class="headerlink" href="#looping" title="Permalink to this heading"></a></h2>
<p><strong>Looping Constructs</strong>. <code class="docutils literal notranslate"><span class="pre">while-do-done</span></code> and <code class="docutils literal notranslate"><span class="pre">until-do-done</span></code>
looping constructs are also supported. These work from the command
line but are primarily intended for use within NSH scripts (see
the <code class="docutils literal notranslate"><span class="pre">`sh</span></code> &lt;#cmdsh&gt;`__ command).</p>
<blockquote>
<div><ul>
<li><p><code class="docutils literal notranslate"><span class="pre">while-do-done</span></code>: Execute <code class="docutils literal notranslate"><span class="pre">[sequence</span> <span class="pre">of</span> <span class="pre">&lt;cmd&gt;]</span></code> as long
as <code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span></code> has an exit status of zero. The syntax is as
follows:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="k">while</span><span class="w"> </span>&lt;cmd&gt;
<span class="k">do</span>
<span class="w"> </span><span class="o">[</span>sequence<span class="w"> </span>of<span class="w"> </span>&lt;cmd&gt;<span class="o">]</span>
<span class="k">done</span>
</pre></div>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">until-do-done</span></code>: Execute <code class="docutils literal notranslate"><span class="pre">[sequence</span> <span class="pre">of</span> <span class="pre">&lt;cmd&gt;]</span></code> as long
as <code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span></code> has a non-zero exit status. The syntax is as
follows:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>until &lt;cmd&gt;
do
[sequence of &lt;cmd&gt;]
done
</pre></div>
</div>
</li>
</ul>
</div></blockquote>
<p>Where <code class="docutils literal notranslate"><span class="pre">&lt;cmd&gt;</span></code> is a <a class="reference external" href="#command-overview">simple command</a>. The
command success value of zero is treated true; a non-zero command
failure value is treated false. The <code class="docutils literal notranslate"><span class="pre">`test</span></code> &lt;#cmdtest&gt;`__
command is frequently used for comparisons.</p>
<p><strong>The</strong> <code class="docutils literal notranslate"><span class="pre">break</span></code> <strong>Command</strong>. A <code class="docutils literal notranslate"><span class="pre">break</span></code> command is also supported.
The <code class="docutils literal notranslate"><span class="pre">break</span></code> command is only meaningful within the body of the a
<code class="docutils literal notranslate"><span class="pre">while</span></code> or <code class="docutils literal notranslate"><span class="pre">until</span></code> loop, between the <code class="docutils literal notranslate"><span class="pre">do</span></code> and <code class="docutils literal notranslate"><span class="pre">done</span></code> tokens.
If the <code class="docutils literal notranslate"><span class="pre">break</span></code> command is executed within the body of a loop,
the loop will immediately terminate and execution will continue
with the next command immediately following the <code class="docutils literal notranslate"><span class="pre">done</span></code> token.</p>
</section>
<section id="built-in-variables">
<h2>Built-In Variables<a class="headerlink" href="#built-in-variables" title="Permalink to this heading"></a></h2>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">$?</span></code></p></td>
<td><p>The result of the last simple command execution. <br/>
On backgrounded commands, this variable holds only <br/>
the result of spawning the background command.</p></td>
</tr>
</tbody>
</table>
</section>
<section id="current-working-directory">
<h2>Current Working Directory<a class="headerlink" href="#current-working-directory" title="Permalink to this heading"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">cd</span></code> <strong>and</strong> <code class="docutils literal notranslate"><span class="pre">pwd</span></code>. All path arguments to commands may be
either an absolute path or a path relative to the current working
directory. The current working directory is set using the
<code class="docutils literal notranslate"><span class="pre">cd</span></code> command and can be queried either by using the
<code class="docutils literal notranslate"><span class="pre">pwd</span></code> command or by using the <code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">$PWD</span></code> command.</p>
</section>
<section id="environment-variables">
<h2>Environment Variables<a class="headerlink" href="#environment-variables" title="Permalink to this heading"></a></h2>
<table class="docutils align-default">
<tbody>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">PATH</span></code></p></td>
<td><p>The default path in the file systems to look <br/>
for executable, binary programs working directory</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">PWD</span></code></p></td>
<td><p>The current working directory</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">OLDPWD</span></code></p></td>
<td><p>The previous working directory</p></td>
</tr>
</tbody>
</table>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="index.html" class="btn btn-neutral float-left" title="NuttShell (NSH)" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="commands.html" class="btn btn-neutral float-right" title="Commands" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2023, The Apache Software Foundation.</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>