mirror of https://github.com/vinc/moros.git
243 lines
6.4 KiB
HTML
243 lines
6.4 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>MOROS Shell</title>
|
|
<link rel="stylesheet" type="text/css" href="moros.css">
|
|
</head>
|
|
<body>
|
|
<h1>MOROS Shell</h1>
|
|
|
|
<h2>Configuration</h2>
|
|
|
|
<p>The shell will read <code>/ini/shell.sh</code> during initialization to setup its
|
|
configuration.</p>
|
|
|
|
<h2>Commands</h2>
|
|
|
|
<p>The main commands have a long name, a one-letter alias, and may have
|
|
additional common aliases.</p>
|
|
|
|
<p><strong>Alias</strong> command:</p>
|
|
|
|
<pre><code>> alias d delete
|
|
</code></pre>
|
|
|
|
<!--
|
|
**Append** to file:
|
|
|
|
> a a.txt
|
|
> append a.txt
|
|
-->
|
|
|
|
<p><strong>Delete</strong> file:</p>
|
|
|
|
<pre><code>> d a.txt
|
|
> delete a.txt
|
|
</code></pre>
|
|
|
|
<p><strong>Copy</strong> file:</p>
|
|
|
|
<pre><code>> c a.txt b.txt
|
|
> copy a.txt b.txt
|
|
</code></pre>
|
|
|
|
<p><strong>Move</strong> file:</p>
|
|
|
|
<pre><code>> m a.txt b.txt
|
|
> move a.txt b.txt
|
|
</code></pre>
|
|
|
|
<p><strong>Print</strong> string:</p>
|
|
|
|
<pre><code>> p "Hi"
|
|
> print "Hi"
|
|
</code></pre>
|
|
|
|
<p><strong>Read</strong> file:</p>
|
|
|
|
<pre><code>> r a.txt
|
|
> read a.txt
|
|
</code></pre>
|
|
|
|
<p><strong>Write</strong> file:</p>
|
|
|
|
<pre><code>> w a.txt
|
|
> write a.txt
|
|
</code></pre>
|
|
|
|
<p><strong>Write</strong> dir:</p>
|
|
|
|
<pre><code>> write /usr/alice/ # with a trailing slash to create a dir instead of a file
|
|
</code></pre>
|
|
|
|
<p><strong>List</strong> files in dir:</p>
|
|
|
|
<pre><code>> list /usr/alice
|
|
</code></pre>
|
|
|
|
<p>When executed without arguments, this command will list the files of the
|
|
current directory.</p>
|
|
|
|
<p><strong>Goto</strong> dir:</p>
|
|
|
|
<pre><code>> goto /usr/alice
|
|
</code></pre>
|
|
|
|
<p>When executed without arguments, this command will print the current directory.</p>
|
|
|
|
<h2>Combiners (TODO)</h2>
|
|
|
|
<p><strong>And combiner:</strong></p>
|
|
|
|
<pre><code>> read foo.txt and read bar.txt
|
|
</code></pre>
|
|
|
|
<p><strong>Or combiners:</strong></p>
|
|
|
|
<pre><code>> read foo.txt or read bar.txt
|
|
</code></pre>
|
|
|
|
<h2>Pipes and redirections (WIP)</h2>
|
|
|
|
<p>A thin arrow <code>-></code> can be used for piping the output from one command to the
|
|
input of another command (TODO):</p>
|
|
|
|
<pre><code>> read foo.txt -> write bar.txt
|
|
</code></pre>
|
|
|
|
<p>A fat arrow <code>=></code> can be used for redirecting directly to a file:</p>
|
|
|
|
<pre><code>> read foo.txt => bar.txt
|
|
</code></pre>
|
|
|
|
<p>In the following example the standard output is redirected to the null device
|
|
file while the standard error is kept:</p>
|
|
|
|
<pre><code>> time read foo.txt => /dev/null
|
|
</code></pre>
|
|
|
|
<p>The standard output is implied as the source of a redirection, but it is
|
|
possible to explicitly redirect a handle to another (TODO):</p>
|
|
|
|
<pre><code>> time read foo.txt [1]=>[3]
|
|
</code></pre>
|
|
|
|
<p>Or to redirect a handle to a file:</p>
|
|
|
|
<pre><code>> time read foo.txt [1]=> bar.txt
|
|
</code></pre>
|
|
|
|
<p>Or to pipe a handle to another command:</p>
|
|
|
|
<pre><code>> time read foo.txt [1]-> write bar.txt
|
|
</code></pre>
|
|
|
|
<p>It is possible to chain multiple redirections:</p>
|
|
|
|
<pre><code>> time read foo.txt [1]=> bar.txt [2]=> time.txt
|
|
</code></pre>
|
|
|
|
<p>When the arrow point to the other direction the source and destination are
|
|
swapped and the standard input is implied (TODO):</p>
|
|
|
|
<pre><code>> write <= req.txt => /net/http/moros.cc
|
|
</code></pre>
|
|
|
|
<p>Redirections should be declared before piping (TODO):</p>
|
|
|
|
<pre><code>> write <= req.txt => /net/http/moros.cc -> find --line href -> sort
|
|
</code></pre>
|
|
|
|
<p>NOTE: The following handles are available when a process is created:</p>
|
|
|
|
<ul>
|
|
<li><code>stdin(0)</code></li>
|
|
<li><code>stdout(1)</code></li>
|
|
<li><code>stderr(2)</code></li>
|
|
<li><code>stdnull(3)</code></li>
|
|
</ul>
|
|
|
|
<p>A redirection with a single arrow head will truncate its destination while
|
|
multiple heads like <code>=>></code> will append to it.</p>
|
|
|
|
<p>NOTE: Arrows can be longer, and also shorter in the case of fat arrows:</p>
|
|
|
|
<pre><code>> read foo.txt --> write bar.txt
|
|
> read foo.txt -> write bar.txt
|
|
</code></pre>
|
|
|
|
<!--
|
|
> read foo.txt | write bar.txt
|
|
-->
|
|
|
|
<pre><code>> read foo.txt ==> bar.txt
|
|
> read foo.txt => bar.txt
|
|
> read foo.txt > bar.txt
|
|
|
|
> write bar.txt <== foo.txt
|
|
> write bar.txt <= foo.txt
|
|
> write bar.txt < foo.txt
|
|
|
|
> read foo.txt ==>> bar.txt
|
|
> read foo.txt =>> bar.txt
|
|
> read foo.txt >> bar.txt
|
|
</code></pre>
|
|
|
|
<h2>Variables</h2>
|
|
|
|
<ul>
|
|
<li>Name of the shell or the script: <code>$0</code></li>
|
|
<li>Script arguments: <code>$1</code>, <code>$2</code>, <code>$3</code>, <code>$4</code>, ...</li>
|
|
<li>Exit code: <code>$?</code></li>
|
|
<li>Process environment variable: <code>$HOME</code>, ...</li>
|
|
<li>Shell environment variable: <code>$foo</code>, ...</li>
|
|
</ul>
|
|
|
|
<p>Setting a variable in the shell environment is done with the following command:</p>
|
|
|
|
<pre><code>> set foo 42
|
|
|
|
> set bar "Alice and Bob"
|
|
</code></pre>
|
|
|
|
<p>And accessing a variable is done with the <code>$</code> operator:</p>
|
|
|
|
<pre><code>> print $foo
|
|
42
|
|
|
|
> print "Hello $bar"
|
|
Hello Alice and Bob
|
|
</code></pre>
|
|
|
|
<p>The process environment is copied to the shell environment when a session is
|
|
started. By convention a process env var should be in uppercase and a shell
|
|
env var should be lowercase.</p>
|
|
|
|
<p>Unsetting a variable is done like this:</p>
|
|
|
|
<pre><code>> unset foo
|
|
</code></pre>
|
|
|
|
<h2>Globbing</h2>
|
|
|
|
<p>MOROS Shell support filename expansion or globbing for <code>*</code> and <code>?</code> wildcard
|
|
characters, where a pattern given in an argument of a command will be replaced
|
|
by files matching the pattern.</p>
|
|
|
|
<ul>
|
|
<li><code>*</code> means zero or more chars except <code>/</code></li>
|
|
<li><code>?</code> means any char except <code>/</code></li>
|
|
</ul>
|
|
|
|
<p>For example <code>/tmp/*.txt</code> will match any files with the <code>txt</code> extension inside
|
|
<code>/tmp</code>, and <code>a?c.txt</code> will match a file named <code>abc.txt</code>.</p>
|
|
|
|
<h2>Tilde Expansion</h2>
|
|
|
|
<p>The tilde character <code>~</code> is a shortcut to <code>$HOME</code> so <code>~/test</code> will be expanded
|
|
to <code>$HOME/test</code> by the shell.</p>
|
|
<footer><p><a href="/">MOROS</a></footer>
|
|
</body>
|
|
</html>
|