blob: da5d9766db847ae8637ec6463eadb71d5cb57ba7 [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="viewport" content="width=device-width, initial-scale=1.0">
<title>Overview &mdash; NuttX latest documentation</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx_tabs/semantic-ui-2.4.1/segment.min.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx_tabs/semantic-ui-2.4.1/menu.min.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx_tabs/semantic-ui-2.4.1/tab.min.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx_tabs/tabs.css" type="text/css" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" 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
<img src="../../_static/NuttX.png" class="logo" alt="Logo"/>
</a>
<!-- this version selector is quite ugly, should be probably replaced by something
more modern -->
<div class="version-selector">
<select>
<option value="latest" selected="selected">latest</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" />
<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="main navigation">
<p class="caption"><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="../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Getting Started</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">OS Components</a><ul class="current">
<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>
<li class="toctree-l4"><a class="reference internal" href="#nsh-start-up-script">NSH Start-Up Script</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">Customizing the NuttShell</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>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../power.html">Power Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="../socketcan.html">SocketCAN Device Drivers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../syslog.html">SYSLOG</a></li>
<li class="toctree-l2"><a class="reference internal" href="../binfmt.html">Binary Loader</a></li>
<li class="toctree-l2"><a class="reference internal" href="../drivers/index.html">Device Drivers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../filesystem.html">NuttX File System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../nxflat.html">NXFLAT</a></li>
<li class="toctree-l2"><a class="reference internal" href="../nxgraphics/index.html">NX Graphics Subsystem</a></li>
<li class="toctree-l2"><a class="reference internal" href="../nxwidgets.html">NxWidgets</a></li>
<li class="toctree-l2"><a class="reference internal" href="../paging.html">On-Demand Paging</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../applications/index.html">Applications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../boards/index.html">Supported Boards</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="../../guides/index.html">Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/index.html">Releases</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="../../glossary.html">Glossary</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<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="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
<li><a href="../index.html">OS Components</a> &raquo;</li>
<li><a href="index.html">NuttShell (NSH)</a> &raquo;</li>
<li>Overview</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/components/nsh/nsh.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="overview">
<span id="nsh"></span><h1>Overview<a class="headerlink" href="#overview" title="Permalink to this headline"></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>
<div class="section" id="console-nsh-front-end">
<h2>Console/NSH Front End<a class="headerlink" href="#console-nsh-front-end" title="Permalink to this headline"></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">
<colgroup>
<col style="width: 30%" />
<col style="width: 70%" />
</colgroup>
<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>
</div>
<div class="section" id="command-overview">
<h2>Command Overview<a class="headerlink" href="#command-overview" title="Permalink to this headline"></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">
<colgroup>
<col style="width: 45%" />
<col style="width: 55%" />
</colgroup>
<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> FOO myprogram <span class="nv">$BAR</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> FOO XYZ
<span class="nb">set</span> BAR <span class="m">123</span>
<span class="nb">set</span> FOOBAR 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>
</div>
<div class="section" id="conditional-command-execution">
<h2>Conditional Command Execution<a class="headerlink" href="#conditional-command-execution" title="Permalink to this headline"></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="o">[</span>!<span class="o">]</span> &lt;cmd&gt;
<span class="k">then</span>
<span class="o">[</span>sequence of &lt;cmd&gt;<span class="o">]</span>
<span class="k">else</span>
<span class="o">[</span>sequence of &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="#cmdoverview">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>
</div>
<div class="section" id="looping">
<h2>Looping<a class="headerlink" href="#looping" title="Permalink to this headline"></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> &lt;cmd&gt;
<span class="k">do</span>
<span class="o">[</span>sequence of &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="#cmdoverview">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>
</div>
<div class="section" id="built-in-variables">
<h2>Built-In Variables<a class="headerlink" href="#built-in-variables" title="Permalink to this headline"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<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>
</div>
<div class="section" id="current-working-directory">
<h2>Current Working Directory<a class="headerlink" href="#current-working-directory" title="Permalink to this headline"></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>
</div>
<div class="section" id="environment-variables">
<h2>Environment Variables<a class="headerlink" href="#environment-variables" title="Permalink to this headline"></a></h2>
<table class="docutils align-default">
<colgroup>
<col style="width: 17%" />
<col style="width: 83%" />
</colgroup>
<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>
</div>
<div class="section" id="nsh-start-up-script">
<h2>NSH Start-Up Script<a class="headerlink" href="#nsh-start-up-script" title="Permalink to this headline"></a></h2>
<p><strong>NSH Start-Up Script</strong>. NSH supports options to provide a start
up script for NSH. In general this capability is enabled with
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ROMFSETC</span></code>, but has several other related
configuration options as described with the <a class="reference external" href="#nshconfiguration">NSH-specific
configuration settings</a>. This capability
also depends on:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_DISABLE_MOUNTPOINT</span></code> not set</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_NFILE_DESCRIPTORS</span></code> &gt; 4</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_FS_ROMFS</span></code> enabled</p></li>
</ul>
</div></blockquote>
<p><strong>Default Start-Up Behavior</strong>. The implementation that is provided
is intended to provide great flexibility for the use of Start-Up
files. This paragraph will discuss the general behavior when all
of the configuration options are set to the default values.</p>
<p>In this default case, enabling <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ROMFSETC</span></code> will cause
NSH to behave as follows at NSH startup time:</p>
<blockquote>
<div><ul>
<li><p>NSH will create a read-only RAM disk (a ROM disk), containing a
tiny ROMFS file system containing the following:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>`--init.d/
`-- rcS
</pre></div>
</div>
<p>Where rcS is the NSH start-up script.</p>
</li>
<li><p>NSH will then mount the ROMFS file system at <code class="docutils literal notranslate"><span class="pre">/etc</span></code>,
resulting in:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>|--dev/
| `-- ram0
`--etc/
`--init.d/
`-- rcS
</pre></div>
</div>
</li>
<li><p>By default, the contents of rcS script are:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX
mkrd -m 1 -s 512 1024
mkfatfs /dev/ram1
mount -t vfat /dev/ram1 /tmp
</pre></div>
</div>
</li>
<li><p>NSH will execute the script at <code class="docutils literal notranslate"><span class="pre">/etc/init.d/rcS</span></code> at start-up
(before the first NSH prompt). After execution of the script,
the root FS will look like:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>|--dev/
| |-- ram0
| `-- ram1
|--etc/
| `--init.d/
| `-- rcS
`--tmp/
</pre></div>
</div>
</li>
</ul>
</div></blockquote>
<p><strong>Modifying the ROMFS Image</strong>. The contents of the <code class="docutils literal notranslate"><span class="pre">/etc</span></code>
directory are retained in the file <code class="docutils literal notranslate"><span class="pre">apps/nshlib/nsh_romfsimg.h</span></code>
OR, if <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS</span></code> is defined,
<code class="docutils literal notranslate"><span class="pre">include/arch/board/rcs.template</span></code>). In order to modify the
start-up behavior, there are three things to study:</p>
<blockquote>
<div><ol class="arabic">
<li><p><strong>Configuration Options.</strong> The additional
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ROMFSETC</span></code> configuration options discussed with
the other <a class="reference external" href="#nshconfiguration">NSH-specific configuration
settings</a>.</p></li>
<li><p><cite>tools/mkromfsimg.sh`</cite> <strong>Script</strong>. The script
<code class="docutils literal notranslate"><span class="pre">tools/mkromfsimg.sh</span></code> creates <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code>. It is not
automatically executed. If you want to change the configuration
settings associated with creating and mounting the <code class="docutils literal notranslate"><span class="pre">/tmp</span></code>
directory, then it will be necessary to re-generate this header
file using the <code class="docutils literal notranslate"><span class="pre">tools/mkromfsimg.sh</span></code> script.</p>
<p>The behavior of this script depends upon three things:</p>
<ul class="simple">
<li><p>The configuration settings then installed configuration.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">genromfs</span></code> tool (available from
<a class="reference external" href="http://romfs.sourceforge.net">http://romfs.sourceforge.net</a>).</p></li>
<li><p>The file <code class="docutils literal notranslate"><span class="pre">apps/nshlib/rcS.template</span></code> (OR, if
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS</span></code> is defined
<code class="docutils literal notranslate"><span class="pre">include/arch/board/rcs.template</span></code>.</p></li>
</ul>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">rcS.template</span></code>: The file <code class="docutils literal notranslate"><span class="pre">apps/nshlib/rcS.template</span></code>
contains the general form of the <code class="docutils literal notranslate"><span class="pre">rcS</span></code> file; configured
values are plugged into this template file to produce the final
<code class="docutils literal notranslate"><span class="pre">rcS</span></code> file.</p></li>
</ol>
</div></blockquote>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">apps/nshlib/rcS.template</span></code> generates the standard,
default <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code> file. If <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS</span></code> is
defined in the NuttX configuration file, then a custom,
board-specific <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code> file residing in the
<code class="docutils literal notranslate"><span class="pre">boards/&lt;arch&gt;/&lt;chip&gt;/&lt;board&gt;/include</span></code> directory will be used.
NOTE when the OS is configured, <code class="docutils literal notranslate"><span class="pre">include/arch/board</span></code> will be
linked to <code class="docutils literal notranslate"><span class="pre">boards/&lt;arch&gt;/&lt;chip&gt;/&lt;board&gt;/include</span></code>.</p>
</div>
<p>All of the startup-behavior is contained in <code class="docutils literal notranslate"><span class="pre">rcS.template</span></code>. The
role of <code class="docutils literal notranslate"><span class="pre">mkromfsimg.sh</span></code> is to (1) apply the specific
configuration settings to <code class="docutils literal notranslate"><span class="pre">rcS.template</span></code> to create the final
<code class="docutils literal notranslate"><span class="pre">rcS</span></code>, and (2) to generate the header file <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code>
containing the ROMFS file system image.</p>
<p><strong>Further Information</strong>. See the section on <a class="reference external" href="#customizingnsh">Customizing the
NuttShell</a> for additional, more detailed
information about the NSH start-up script and how to modify it.</p>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2020, The Apache Software Foundation
</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>