%THE HELIOS SHELL MANUAL, PUBLISHED NOVEMBER 1991.
%PLEASE IGNORE THE `overfull h-box' MESSAGES (26.47054pt, 6.82878pt) 
%GENERATED BY THIS FILE: THEY HAVE NO EFFECT ON THE FINAL OUTPUT.
%$Id: HEL91001.tex,v 1.1 1992/01/23 18:10:24 doc Exp $

\documentstyle[times,a5,makeidx,bezier,epic]{psl}
\makeindex

\newcommand{\rightang}{$>$}
\newcommand{\leftang}{$<$}
\newcommand{\dblleftang}{$<<$}
\newcommand{\dblrightang}{$>>$}
\newcommand{\vrt}{{\tt |}}

\title{\Huge {\bf The Helios Shell}}
\author{}
\date{}

\pagestyle{empty}
\begin{document}

\include{docinfo}

\docinfotitle{The Helios Shell}
\docinfoauthor{PERIHELION SOFTWARE LIMITED}
\docinfoproject{HEL}
\docinfoauthinit{PSL}
\docinfoyear{91}
\docinfodocno{001}
\docinforev{1}
\docinfooperator{ID}
\docinfostate{APPROVED}
\docinfosecurity{PUBLISHED 1991}
\docinforeader{PSL}

\maketitle
\setcounter{tocdepth}{4}
%\pagenumbering{roman}
%\tableofcontents
\include{HEL91004}
\pagestyle{plain}

\cleardoublepage
\pagenumbering{arabic}


\newlength{\tsep}
\setlength{\tsep}{0.15in}
\newlength{\titlesep}
\setlength{\titlesep}{0.25in}




\section*{1 Introducing the Helios shell}

This guide is divided into two parts: the first part describes simple
use of the Helios shell, including the most common activities; the second part
describes more advanced use of the shell. 

Helios provides a task called the Helios shell, which
acts as a command line interface to the operating system. 
Within the Helios shell the user can give all the Helios commands, including
the one-line, built-in shell
commands. These shell commands were intentionally
designed to be similar enough to Unix shell commands for Unix users to feel 
at home. However, Unix users should note that not all Unix shell commands
are available in Helios and that commands with identical names in both shells
may not act in exactly the same way.
\index{Helios!shell - Unix compatibility}
\index{Unix!compatibility of shell}
\index{Compatibility!Helios shell to Unix}

The Helios shell also includes various shorthand methods to
save typing, and personalisation methods to help users to create their own
commands. Several shells can be used simultaneously, if this is
desirable.

\section*{2 Using the shell}

This section provides an introduction to the most commonly used features
within the Helios shell. It is intended that this section will be sufficient
for the novice user. Anyone who requires a more detailed explanation is
advised to consult chapter 3.


\subsection*{2.1 Giving commands to the shell}

The simplest kind of command is a single word,
\index{word@{\bf word} - shell command line}
\index{Shell command line!word@{\bf word}}
where a word is one or more characters delimited by blank space, tabs,
or by the beginning or end of the line.  The entire line is known
as a {\bf command line}. The simple command:
\index{ls@{\bf ls} - command}

\begin{verbatim}
    ls
\end{verbatim}
tells the shell to provide a list of the contents of the current
directory.

A command may include a whole sequence of words,
where the first word specifies the command and the rest qualify its
action. These qualifying words or {\bf arguments} include {\bf options}. Options
are built-in alternatives associated with a particular command. They
are usually keywords of the form `-$x$' that determine
what optional action a command must take. Options are usually given
after the command. For example,
\index{Command!description of commands}
\index{Arguments (command qualifiers)}
\index{Command!qualifiers!options}
\index{Command!qualifiers!arguments}
\index{Options!(command qualifiers)}


\begin{verbatim}
   ls -l
\end{verbatim}
tells the shell to provide a list as before, but with even greater
detail. Other arguments may include the name of a file to be edited.
For example,

\begin{verbatim}
   ls -l myfile
\end{verbatim}
tells the shell to give the same sort of details as above, only this time
just for the file named `myfile'. Notice the option `-l' goes before the other
argument; this is always the order.

\subsection*{2.2 Filename/command completion}

\index{Command!completion - shell}\index{Shell!command completion}
\index{Filename!completion - in shell}\index{Shell!filename completion}
\index{Command!/filename completion in shell}
There is a useful feature of the Helios shell that saves a lot of typing
at the keyboard. Type the
first few letters of a filename, or of a command
name, and then press the escape key. The shell  automatically
completes the name, if it can,
\index{ESCAPE!use of in shell}
\index{Control@CTRL-D - use of in shell}
by matching the characters  typed to the range of names available.
Although this feature can be used for names of any length, it is
most useful for long names. If the key sequence CTRL-D is used instead
of pressing the escape key, a list of possible options or matches for
the specified command or directory name is produced.

\index{Automatic!name completion}\index{Name completion!automatic}

\subsubsection*{2.2.1 Name completion using ESC}

Press the escape key (ESC) after typing one or more characters, and this will
cause the shell to search for a name that begins with that
sequence of characters. The shell can determine whether to look
for a command name or a filename or directory name by its context and
relative position on the command line.
If the shell finds a file with a name which begins with the 
characters  typed, it completes the filename 
and displays the result
on the screen. If it finds that more than one file
shares the same initial characters, it appends as many characters
as it can to form a stub that is common to all the possible files and then
signals an error by sounding the terminal's bell. When this situation arises,
either complete the file name, or add a few extra
characters before re-using the escape key. 
For example, instead of typing:

\begin{verbatim}
   cd examples
\end{verbatim}
the user could enter the following:

\begin{quote}
   \tt cd ex{\em ESC}
\end{quote}


The escape key then forces the shell to complete the name, {\tt examples}. 
Similarly, give:

\begin{quote}
   \tt da{\em ESC}
\end{quote}
and the shell supplies the last two letters to complete the command name {\bf date}.
The user can then press the return key to
execute {\bf date}. However, give:

\begin{quote}
   \tt d{\em ESC}
\end{quote}
and the shell sounds a terminal bell to show that it does not know how
to complete the name because there is more than one name that starts
with the letter `d'. 

\subsubsection*{2.2.2 Name completion using CTRL-D}

\index{Automatic name completion}\index{Name completion!automatic}
As an alternative to the escape key, use the control combination
CTRL-D. This combination
causes the shell to list all the files with names that begin with
the specified stub. It then redisplays the text entered,
enabling the user to complete the name with its correct ending.

Suppose, for example, the directory `fred' contains two files:
one is called {\bf test.tst} and the other is {\bf test.txt}. In this 
case the command line:

\begin{quote}
   \tt cat /fred/te{\em ESC}
\end{quote}
will be ambiguous as the stub,
`te', refers to more than one file. The shell will attempt to complete the
name, adding as many characters as it can before signalling an error:

\begin{quote}
   \tt /fred/test.t
\end{quote}


At this point there are three options: complete the name,
add an `s' and use the escape key to force the shell 
\index{Name completion}\index{Name completion!automatic}
\index{Automatic name completion}
to complete the name, or
\index{Control@CTRL-D}
use CTRL-D to list all the files with names which begin with `test.t'.

When using CTRL-D, there is no need to worry about using 
characters that might match more than one name. Take an example
used earlier: the letter `d' followed by ESC. Suppose that CTRL-D had been used
instead of ESC: 

\begin{quote}
   \tt d{\em CTRL-D}
\end{quote}
the shell would have provided a list something like this:

\begin{quote}
      \tt date* df* diff* dump*
\end{quote}
enabling the user to find the correct command, complete it, and  execute it.
\vfill
\newpage

\subsection*{2.3 Simple shell input and output}

This section describes the control of input and output through the
use of redirection and pipes.

\subsubsection*{2.3.1 Redirection}

\index{I/O!redirection of}
\index{Redirection!of I/O}
\index{Input!to the shell}\index{Shell!input}
When using the shell,
commands are generally issued by typing them in at the keyboard. The
keyboard is the default method of input; it is
what is meant by {\bf standard input} ({\bf stdin}). The shell usually returns any output by
`printing' it on the
screen, unless it is requested to do otherwise. This default output is known
as the {\bf standard output} ({\bf stdout}). 
\index{Standard!output}\index{Output!standard}
\index{Output!from the shell}\index{Shell!output}
\index{stdout@{\bf stdout}}


For example, type the command:

\begin{quote}
      \tt ls
\end{quote}
and the contents of the current directory appear on the screen like this:

\begin{quote}
      \it file1     file2     file3
\end{quote}
followed by the current prompt on a line by itself.
If there is no output, the shell indicates that it has executed the
command by returning a prompt to the screen. The default prompt is a
\index{Shell!prompt}
percentage sign: 
\begin{verbatim}
      %
\end{verbatim}

The user may wish to redirect the output to somewhere other than the 
standard output. This can be done by including a {\bf greater than} 
symbol \rightang
\index{\rightang redirection of I/O}
\index{Redirection!of I/O!\rightang}
within the command, followed by the name of the destination. 
To send the contents of the current directory 
to the file {\bf contents}, type:

\begin{quote}
   \tt ls \verb+>+ contents
\end{quote}


It does not matter if the \rightang
symbol is surrounded with blank space or not. The
shell treats \rightang as a separate word with a meaning of its own and not
as part of the command or its argument. For example, 

\begin{quote}
   \tt ls\verb+>+contents
\end{quote}

\noindent would be equally acceptable.
If the file {\bf contents} does not exist, it is created; 
otherwise, this command line will
overwrite everything in {\bf contents} with the output of {\bf ls}. 
To ensure that the output is added to the
end of an existing file instead of overwriting it, give a 
{\bf double greater than} symbol \dblrightang instead.

\index{\dblrightang redirection of I/O}
\index{Redirection!of I/O!\dblrightang}
\index{\leftang redirection of I/O}
\index{Redirection!of I/O!\leftang}
To take input from somewhere other than the standard input,
precede the name of the input source (often this is the name of a file,
the contents of which are to be directed to the {\bf stdin} of the command),
with a {\bf less than} symbol \leftang. 
Again, it can be given immediately before the name or separated from it it with blank space.

\subsubsection*{2.3.2 Pipes}

\index{Pipes}
\index{Pipelines of commands}
\index{$\mid$ pipes in shell}\index{Shell!pipes}
Whereas redirection can be used to force a process to communicate with files
instead of with a terminal, pipes can be used to make processes communicate
directly with other processes. This is particularly useful when running
a command with an output which needs to be sent directly to the input of a second
program for further processing.
As an example of pipelining, consider the following:

\begin{quote}
   \tt ls \verb+|+ wc -w
\end{quote}


In this case, the output from {\bf ls} (a list of all the files in the current
directory) is being used as the input to {\bf wc} ({\em word count\/}). 
{\bf wc} 
with the {\bf -w} option counts the number of words and displays the 
result on the screen. This executes {\bf ls} and {\bf wc},
simultaneously piping the output ({\bf stdout}) of {\bf ls} to the input ({\bf
stdin}) of {\bf wc}.
The overall effect of this command line is to count the number of files
in the current directory.

\subsection*{2.4 The history facilities}
\index{Using!the history list}
\index{History!list}
\index{Event!list - see history list}

The shell stores in memory each command typed into it, and places these
commands on a list of past events.
The shell allows the user to recall this 
list to review previous actions, to repeat a command, or to edit a
previous command before executing it again. The user can even specify the number
of previous commands which will be retained in the list by assigning a value to the
shell variable {\bf history}. If {\bf history} has not been set, or has been assigned
a value of 
0, only the most recent command will be retained.
\index{History!list (size of)}
\index{history@{\bf history} - shell variable}
\index{Shell variable!history@{\bf history}}

\begin{sloppypar}
Each event on the history list is associated with a
\index{History!event numbers}\index{Event!numbers!history}
\index{Event!numbers}
number, starting with 1 and increasing sequentially. As each event
occurs,
it is added
to the list. The number appears to the left of the event when the 
\index{history@{\bf history} - shell command}
\index{Shell command!history@{\bf history}}
events are listed with {\bf history}. For example, the last four events might look
like this
when listed:
\end{sloppypar}

\begin{verbatim}
     100 date
     101 ls -l
     102 cd newfile
     103 history
\end{verbatim}

(Notice that {\bf history} is included as the most recent event, 
number 103). 
To find out the current event number without resorting to
the {\bf history} command, place a {\tt !} character in the
prompt string. The prompt string is merely the first word
of the shell variable {\bf prompt}. For example, type:
\index{"!}
\index{Repeating!commands}\index{Command!repetition of}
\index{prompt@{\bf prompt} - shell variable}
\index{Shell variable!prompt@{\bf prompt}}
\index{Prompt!in shell}\index{Shell!prompt}

\begin{quote}
   \tt set prompt="! : "
\end{quote}

\noindent and the shell prompts with:

\begin{quote}
   \tt 104 :
\end{quote} 

\noindent or whatever the event number is at present, followed by a colon. The shell
then continues to increment this number with each new event.
\index{"!!}
\index{Repeating!commands}\index{Command!repetition of}

To access an event and re-introduce it as current input,
use the exclamation mark (!) character. A pair of these characters 
followed by 
{\bf newline} tells the shell to access the last event, {\bf echo} it to the terminal, 
substitute it as the current line of input and repeat its action. To
do this with any other event on the list, be more specific. 
The ! character can be followed by the number of the event to be
accessed. To re-execute the {\bf date} command,
type:

\begin{quote}
   \tt !100
\end{quote}


\noindent The shell will display the event associated with that number
and  execute it:

\begin{verbatim}
     date 
     FRI JAN 29 13:22:07 1991 
     105: 
\end{verbatim}

\index{Repeating!previous commands}\index{Command!repetition of previous 
commands}
\index{Repeating!past events}\index{Past events - repetition of}
\index{Events!past}

An event can be referred to by its position in relation to the current event
using a minus sign followed by an integer, where the integer
refers to the number of events to go back on the list. For example,
suppose the user knows that the current event number is 106 (because
the current prompt is set up to reflect event numbers) 
and the user types {\tt !-6}:

\begin{quote}
   \tt 106 : !-6
\end{quote}


The shell will act as if they had typed
{\tt !100} (in other words, 6 from 106 translates 
as event number 100).

An event can be retrieved from the history list by following
! with as many characters of the command name as will specify it
exactly. The shell searches backwards from the current event until it
finds the first match in the history. It then repeats that command.
For example, to repeat the last command beginning with `d', 
type:
\index{"!}
\index{Repeating!events}

\begin{quote}
   \tt !d
\end{quote}


Take care that the last command with this initial letter is the command
sought. It may be useful to use two or more letters after
the ! to ensure that the correct event is pinpointed and retrieved.

\index{History!list - interactive use of}\index{List!interactive use 
of history list}
\index{Interactive!use of history list}\index{Repeating!events}
\index{Events!repetition of}
The above examples simply show how to capture a past event and
re-introduce it verbatim as current input. The user can, however, 
retrieve a past event 
from the history list, make some changes and then re-execute the 
edited command line. Certain control-key
combinations allow the retrieval of command lines from the history list and then
position the cursor for inserting text into the line or deleting text
from it. A list of these control keys is given below.
\index{Editing!of command line}
\index{Command!line!editing}
\index{Cursor!positioning in command line}\index{Command!line!cursor 
positioning in}
\index{Control!keys used in shell}\index{Shell!control keys}

%THIS TABLE CAN BE PRINTED AS A HANGINDENTED LIST ALSO (SEE BELOW, 
%IN `DESCRIPTION' FORMAT).
\begin{sloppypar}
\begin{table}[h]
\begin{tabular}{ll}
\bf CTRL-A & Moves the cursor to the start of a line.\\
\\
\bf CTRL-B & Moves the cursor to the left by one character.\\
\\
\bf CTRL-E & Moves the cursor to the end of a line.\\
\\
\bf CTRL-F & Moves the cursor to the right by one character.\\
\\
\bf CTRL-L & Moves the cursor to the left by one word.\\
\\
\bf CTRL-N & Replaces the current line with the next line in the history list. 
This\\ & can be used  repeatedly to display each line in the list.\\
\\
\bf CTRL-P & Replaces the current line with the preceding line in the history list.
\\ & This can be  used repeatedly to display each line in the list.\\
\\
\bf CTRL-R & Replaces the current line with \hspace{1mm} one from the history list which be-\\
& gins with the  same word as at the cursor's current position. When\\
& CTRL-R is used on a blank line the last command is fetched from\\ 
& the history list.\\
\\
\bf CTRL-U & Deletes the entire line.\\
\\
\bf CTRL-W & Moves the cursor to the right by one word.\\
\\
\bf CTRL-X & Deletes the word at the cursor.\\
\\
\end{tabular}
\end{table}
\end{sloppypar}
%\begin{description}

%\item {\bf CTRL-A} 

%Move cursor to start of line.

%\item {\bf CTRL-B} 

%Move cursor left by one character.

%\item {\bf CTRL-E}  

%Move cursor to end of line.

%\item {\bf CTRL-F}  

%Move cursor right by one character.

%\item {\bf CTRL-L}  

%Move cursor left by one word.

%\item {\bf CTRL-N}  

%Replace current line by the next line in the history list. 
%This can be used repeatedly to display each line in the history list.

%\item {\bf CTRL-P}  

%Replace current line with the previous line in the history 
%list. This can be used repeatedly to display each line in the history list.

%\item {\bf CTRL-R}  

%Replace current line with a line from the history list 
%which begins with the same word as that at the current cursor position.
%If CTRL-R is used on a blank line the last command is fetched from
%the history list.

%\item {\bf CTRL-U}  

%Delete the entire line.

%\item {\bf CTRL-W}  

%Move cursor to the right by one word.

%\item {\bf CTRL-X}  

%Delete the word at the cursor.

%\end{description}

{\bf Note:} the `up' and `down' arrow keys can also be used to scroll
through the history list.

\subsection*{2.5 Wildcards}

\index{Wildcards}
\index{Asterisk - wildcard for group of characters}
\index{"* wildcard for group of characters}
\index{Question mark symbol - wildcard for single character}
\index{"? wildcard for single character}
\index{Square brackets symbol for wildcards}
\index{"[ for wildcards}
Whenever a filename can be given, wildcards can be used as a shorthand method
for entering the name. One of these wildcards is \verb+*+, which instructs the
shell to replace that character with as many characters as are necessary to
produce a valid filename. Another wildcard character, \verb+?+, has a similar
meaning, but will only be replaced by a single character. 
\verb+[+{\it abc}\verb+]+ can also be used to specify the match of a single character
with one of a group of characters, but this type of 
wildcard will only
match with a character if it is listed within the brackets.

When substituting for wildcards, the shell will use any characters which
are adjacent to the wildcard  to generate a pattern which will be
compared with each of the filenames in a directory.
A list of filenames which match this pattern is then generated and inserted 
into the command line in place of the word which contained the wildcard. 

To determine which directories are searched during wildcard substitution,
consider the wildcard's position within the command line.
If the character appears within a command name, each of the directories
which have been assigned to the shell variable {\bf path} will be searched. If,
however, the wildcard appears within a command's argument, only the
current 
directory will be searched.
Listed below are a few examples of wildcard usage.

\vspace{0.5cm}


\begin{description}

\item \verb+*+
  
General wildcard. Represents a series of characters.
For example, \verb+rm *+ deletes all the files in the current
directory, \verb+rm *.c+ deletes all the files in the current directory
with names which end in {\em.c} and \verb+rm Pe*.c+ deletes all the files in
the current directory with names which begin with {\em Pe} and end with {\em
.c}, such as {\em Perihelion.c}.

\item \verb+?+ 

Wildcard for one character only. For example,
\verb+ls ?a.c+ lists all the files with names which consist of four
characters, where the last three characters are known to be {\em a.c}.
This could match {\em aa.c, ba.c,} etc.

\item \verb+[...]+

Wildcard for one character, but it only matches with
the specified characters. For example, \verb+od t.[abc]+ displays
the contents of the files {\em t.a, t.b} and {\em t.c}.
\end{description}

\subsection*{2.6 Running tasks in the background}

\index{Background!tasks}\index{Tasks!background tasks}
The Helios shell allows the running of a task, or pipeline of tasks, without
the need to wait for its completion, by using the ampersand character, 
{\bf \&}. \index{\& shell metacharacter}
This metacharacter, when appended to  a pipeline, causes the entire
pipeline to be run in the background, which frees the shell so that it can
process the next command line, which may also be run in the background.

\index{Job numbers in shell}\index{Shell!job numbers}
\begin{sloppypar}
Whenever a task is executed in the background, the shell assigns a job
number to that task. This job number is displayed on the standard output
device when the task begins to execute and it is also displayed alongside
a suitable message when the task has completed. As each task has a unique
job number, many commands use it to identify a particular task. The {\bf jobs} 
command for example, lists all of the current tasks and their job numbers.
\index{jobs@{\bf jobs} - shell command}
\index{Shell command!jobs@{\bf jobs}}

It should be noted that the output of tasks running in the background is
directed to {\bf stdout} unless otherwise redirected, so there is a
possibility of interference with the output of tasks running in the
foreground. 
As an example of how to use the background facilities, consider the following:
\index{grep@{\bf fgrep} - command}
\end{sloppypar}

\begin{verbatim}
     fgrep Helios huge > Helios &
\end{verbatim}


\begin{sloppypar}
In this example {\bf fgrep} is being used to search for all occurrences of
the word `Helios' within the file `huge'. As this task may take some time to
complete, it is useful to be able to run it in the background, so that other
tasks can be completed simultaneously. When this task begins executing, the
shell will display the following type of message on the screen, followed by
a shell prompt:
\end{sloppypar}

\begin{verbatim}
     [1] 1234
\end{verbatim}


\begin{sloppypar}
This shows that the task has been assigned the job number 1 and that it
has a process identification number of 1234. When the task terminates, the
following message will be displayed:
\end{sloppypar}


\begin{verbatim}
     [1]      Done    fgrep Helios huge
\end{verbatim}


\begin{sloppypar}
\noindent indicating that job number 1 completed successfully.
Several tasks can be executed simultaneously either by using many command
lines, such as that described above, or by constructing a single compound
command line. The following example shows how two background processes and
one foreground process can be invoked from within a single command line:
\end{sloppypar}

\begin{verbatim}
fgrep Helios huge > helios & fgrep Perihelion huge > 
perihelion & echo hello
\end{verbatim}


\begin{sloppypar}
In this example, two instances of the {\bf fgrep} command are being executed in
the background (the \rightang symbol shows that all output is to be sent to a file
instead of to the screen) and one {\bf echo} command is being executed in the
foreground. The shell 
lists the job and the process identification for each of the two background
tasks and then executes each command: 
\end{sloppypar}

\begin{verbatim}
     [1] 1234
     [2] 1235
\end{verbatim}


\noindent Similar messages to that shown above will be displayed when each process
terminates.

\subsection*{2.7 Aliases}

\index{Aliases!within shell}\index{Shell!aliases in}
In its simplest form, the aliasing mechanism allows alternative names to
be associated with a command name. This is particularly beneficial to users
who are not familiar with Unix-style commands, as each command can be assigned
an alternative name which more
closely matches that of a more familiar
operating system. A particularly good example of this is the {\bf ls} command.
Users who are more familiar with the MS-DOS equivalent, {\bf dir}, may therefore
\index{dir@{\bf dir} - typical example of aliasing}
alias {\bf dir} to be equivalent to {\bf ls}, so that either name can be used:
\begin{quote}
   \tt alias dir ls
\end{quote}


The command {\bf dir} can now be used to list the contents of the current directory.
An extension of this idea is to assign an alias to a command and its arguments.
By
default, the {\bf ls} command produces a list of the files in the current directory.
However, a command that lists all the files along with their
creation dates and other information may be preferable to some users. 
This effect can be achieved by invoking
{\bf ls} with the {\bf -l} option, or by assigning an alias to produce a command
with default behaviour which gives this more detailed list of files:
\begin{quote}
   \tt alias ls 'ls -l'
\end{quote}


The use of the above alias will cause all references to the command 
called {\bf ls} to be
replaced with {\bf ls -l}. (Notice the use of the quote characters
to ensure that the command {\bf ls -l} is treated as a single word.)
\vfill
\newpage

\subsection*{2.8 Shell variables}

\index{Shell!variables}
\index{Variables in shell}
The Helios shell supports a list of variables which can be assigned values.
These variables may then appear within command lines where they will be 
substituted for their values. Some of these variables are created and
maintained by the shell (such as {\bf cwd}, which always contains the name
of the current working directory) but others can be created or removed
at will by the user.
A particularly useful application of shell variables is as a shorthand for
long filenames. Consider, for example, the following assignment:
\begin{quote}
   \tt set h=/usr/perihelion/helios
\end{quote}

\index{Assignments!to shell variables}
\index{Shell!variables!assignment to}
\index{Variables!shell!assignments to}
\begin{sloppypar}
The above command results in the creation of a shell variable {\bf h},
which is assigned the value {\bf /usr/perihelion/helios}. If the 
shell finds the character
sequence {\bf \$h} within any future command line,
it performs a variable substitution which causes those
two characters to be replaced with the value of the variable {\bf h}. The
following two command lines are therefore equivalent:
\end{sloppypar}

\begin{verbatim}
   emacs $h/test.c
   emacs /usr/perihelion/helios/test.c
\end{verbatim}


\index{Shell!variables!name length}
\index{Length of shell variable names}
\index{Variables!shell!name length}
Variable names may consist of up to 20 alphanumeric
characters. If such names are used,
it may be necessary to use braces, {\bf \{\}}, to enclose the name whenever
it is used within a command line. This allows the shell to distinguish
between characters which form part of the variable name and those which
form part of the following text. Braces can be omitted if the variable name
is followed by any non-alphanumeric character, including a blank space:

\begin{verbatim}
   set helios=/usr/perihelion/helios

   cd ${helios}/bin
   ls $helios
\end{verbatim}


A shell variable can be assigned new values by reapplying the {\bf set} command,
and they can be deleted with the {\bf unset} command. 

\subsection*{2.9 Using shell windows}
\index{Using!shell windows}
\index{Shell!windows}
\index{Windows!using}
\index{wsh@{\bf wsh} - shell windows}

A child shell is created from within the original parent shell with
{\bf wsh}. This command creates a window and then executes a shell
within it. This newly created shell is independent of 
other shells in other windows and it can be used to \linebreak execute commands
concurrently with them.

The way in which these windows are displayed on the screen
is dependent upon which I/O processor is being used, and so is their user 
interface.
\index{Windows!with IBM host}
\index{IBM!display of windows}
Transputer systems that use an IBM PC (or equivalent) may not be able to
display more than one window at a time. For these systems a virtual 
windowing system is used whereby each window occupies the entire screen.
A process running in any of these windows may write to the screen at
any time, but only the currently active window will receive input from the
keyboard. To change the currently active window and so redirect the
\index{Changing!windows on IBM}
\index{Windows!changing on IBM host}
standard input to another window, use ALT-F1. Repeated use of this
key combination will cycle  through the available windows.

\index{Windows!on graphics systems}
\index{Graphical display of windows}
For systems that are capable of displaying windows, each
call to {\bf wsh} results in a new window being created on the screen. 
The window that is active can be identified by a highlighted title.
A window can be selected by moving the mouse over it or by clicking the
mouse on the window, depending on the window manager used.

\section*{3 An advanced description of the shell}
\label{advanced}

\index{Execution!of the shell}
\index{Shell!executing}
The Helios shell is executed whenever a user logs into the system, or it can
be started from within an existing shell by using either of the commands
{\bf shell} or {\bf wsh}.
The first stage is to execute each of the commands that are 
listed in the shell script, {\bf cshrc}, which should be in the user's home
directory. If the shell is a login shell, 
the commands listed in the file `login' will also be executed.
When creating a child shell by using  the command {\bf shell}, 
various options and arguments can be specified, as follows:
\index{Shell!command line options}\index{Command!line!shell options}
\index{Options!for shell command line}
\begin{quote}
   \tt shell~[~-cefinstvxVX~]~[~arg1~\ldots argn~]
\end{quote}


The argument strings generally do not affect the behaviour of the shell
and are stored in the shell variable {\bf argv}. The option flags are used
\index{argv@{\bf argv}}
to modify the behaviour of the shell and are listed below.
\vspace{0.25cm}

\noindent {\bf Option} \hspace{1cm} {\bf Action}
\vspace{0.25cm}

\begin{description}

\item {\bf c} 

Assumes the (single) following argument to be 
a command line which is to be executed. Any arguments which
follow are copied into the shell variable {\bf argv}.\index{argv@{\bf argv}}

\item {\bf e} 

Causes the shell to terminate if any command 
executed from within the shell produces an error.

\item {\bf f} 

Prevents the shell from reading and executing the commands
in the file {\bf cshrc} when it is invoked.

\item {\bf i} 

Causes the shell to run interactively and to display prompts.
Command line editing is then available and the prompt is displayed. Without
this option the shell tries to discover what type of input has been specified.
This option is an override mechanism.

\item {\bf n}  

Causes all commands entered 
into the shell to be parsed but not executed. This
facility is useful for checking the syntax of shell scripts.

\item {\bf s} 

Instructs the shell to take input from the standard input device.

\item {\bf t} 

Causes the shell to read just one line of commands, 
and then to terminate.

\item {\bf v} 

Causes the shell variable {\bf verbose} to be set. All command lines
will be {\bf echoed} to the screen after history substitution has been performed.

\item {\bf x} 

Causes the shell variable {\bf echo} to be set. All commands
will be {\bf echoed} to the screen before execution.


\item {\bf V} 

Causes the shell variable {\bf verbose} to be set. It differs
from {\bf v} (see above) in that this option sets the verbose mode before the
shell reads {\bf cshrc}; the other option does not.

\item {\bf X} 

Causes the shell variable {\bf echo} to be set. It differs from {\bf x}
(see above) in that this option sets the {\bf echo} mode before the file 
{\bf cshrc} is read; the other option does not.

\end{description}



\subsection*{3.1 Characters and words}

\index{Words - within shell}\index{Shell!words in}
The shell parses a command line by first splitting the line into
its constituent words. Words, with certain exceptions, are characters that 
are delimited by blank spaces or tabs, or enclosed in pairs of
double quotes. 

\index{Shell!metacharacters}
\index{Special characters in shell}
\index{Metacharacters in shell}
\index{Parser metacharacters}
The exceptions are special
characters that form separate words even if they are not delimited 
by blanks or tabs. These
characters, known as the parser metacharacters, are as follows:
\verb+& | ; < > ( )+.
When doubled into metacharacter pairs such as the following, 
\verb+&& || << >>+ 
each pair forms a single, separate word. 

\index{Backslash - use of within shell}
To make one of these metacharacters part of another word and thereby 
remove its special meaning, place the special backslash
character  \verb+\+ immediately before it. This character makes the shell treat 
a subsequent character as literal text without any special 
meaning. In fact, it has this effect on any single character that follows it. 
For example,
place a  \verb+\+ before a {\bf newline} character (carriage return / linefeed),
and the shell translates that character as a blank space because 
its usual meaning has been removed.

\index{Shell!strings within shell command}
\index{Strings!within shell command}
The Helios shell also understands the concept of a string, which it treats
as part of a word. A string can be made up of one or more characters,
including white space, enclosed in single or double quotes.
Because the shell treats strings as part of a single word, metacharacters
in a string cannot form separate words and spaces and tabs fail to
have their usual effect. As explained previously, cancel the effect
of a {\bf newline} with  \verb+\+; 
nevertheless, attempt to use \verb+\+{\bf newline}
in a string and a real {\bf newline} character is produced.
The differences between strings enclosed in
single quotes and strings enclosed in double quotes are
explained in section 3.2.

\index{Comments in shell scripts}
\index{Shell!comments in shell scripts}
\index{\# - comments in shell scripts}
When the user inputs to the shell indirectly through a shell script (a shell
script is a text file of shell commands), rather than
directly from the terminal, the special character \# can be used to
introduce a comment. When the shell finds a \#, it treats any
subsequent text on the same line of input as a comment and
ignores it.  To turn off the special meaning of this 
character, place the literal character {\tt \verb+\+} immediately before it.

\subsection*{3.2 Strings}

\index{Strings!within shell commands}
\index{Shell!strings in command lines}
Character sequences enclosed in single or double quotes form part of
a word. A complete word can be formed entirely from a string  delimited by
white space, or from character sequences which contain a string. The
quote characters will not form part of the word unless they are preceded by
a backslash character ({\tt \verb+\+}).

\index{Strings!single and double quotes}
\index{Strings!in shell}
Character sequences enclosed in single quotes are subject to history
substitution only. History substitution can be used anywhere
on a command line and always occurs in strings, unless
the history substitution characters are preceded by a backslash. Variable
substitution will only occur in double-quoted strings and alias
substitution never occurs in a string. Notice that {\bf !} must be 
preceded by a backslash to nullify its effect. The only exceptions are that
{\bf !} does not take effect when followed by {\bf space}, {\bf end-of-line}, or
{\tt =}. For example, the {\bf !} would not generate any history substitutions 
in {\tt set prompt="! "}.

\subsection*{3.3 Metacharacters}

\index{Metacharacters in shell}
\index{Shell!metacharacters}
\index{Metacharacter precedence}
\index{Precedence!of metacharacters in shell}
The following metacharacters are listed from left to right in order of
precedence:

\begin{quote}
   \tt | ; || \&\& \& ( ) < > << >>
\end{quote}
such that {\tt |} is the most senior (that is, takes precedence over
everything else) and {\tt \&} is the most junior. {\tt (} and the following
metacharacters do not have any precedence. These characters are listed below,
together with their functions.
%\newpage
\vspace{0.25cm}

\noindent {\bf Character} \hspace{1cm} {\bf Action}
\vspace{0.25cm}

\begin{description}
\item \verb+|+ 

Pipes the output from one process to the input of another.
For example, the command \verb+sort datalist | cat+ 
sorts the file {\bf
datalist} and then it displays the output.

\item \verb+;+ 

Used to separate sequences of pipelines (or single
commands). The shell will fully execute each pipeline before executing
the next. For example, the line \verb+ls ; cat text+ will cause
{\bf ls} to be executed, followed by {\bf cat}.

\item \verb+||+ 

Used to separate two pipelines (or single commands). The
second pipeline will only be executed if the first fails. This
metacharacter is anal\-ogous to the logical OR operator. For
example, in \verb+ls || echo ls failed+, the {\bf echo} command will only be
executed if {\bf ls} fails. It exits with a non-zero return code.

\item \verb+&&+ 

Used to separate two pipelines (or single commands). The
second pipeline will only be executed if the first succeeds. This
metacharacter is anal\-ogous to the logical AND operator. For
example, in \verb+ls test && cat+ \linebreak 
\verb+test+, {\bf cat} will only be executed
if {\bf ls} succeeds. It exits with a zero return code.

\item \verb+&+ 

Puts the task into the background. For example,
\verb+sort bigfile &+ runs the sort program on the file {\bf bigfile} as
a background task. It does not wait for it to terminate.

\item {\tt (} 

Used with a terminating {\tt )} to group together a sequence of
commands to be run in a child shell. For instance, \verb+(cd;pwd)+ lists
the full pathname of the user's home directory, but since it is run in a child
shell, the current directory of the parent shell is unchanged.

\item {\tt )} 

Used with an opening {\tt (} to group together a series of pipelines.
See the entry for {\tt (}.

\item \verb+>+ 

Redirects output from standard output ({\bf stdout}). 
\verb+date > now+ for example, redirects the output of {\bf date} from
{\bf stdout} to a file called {\bf now}. If {\bf now} does not exist, it is
created. If it does exist, it is overwritten.

\item \verb+<+ 

Redirects input from standard input ({\bf stdin}). For
example, \verb+cat < text+ redirects the input of {\bf cat} so that it
is taken from the file called {\bf text}. Since {\bf cat} takes a
filename, the same effect can be achieved with {\bf cat} directly.

\item \verb+>>+ 

Redirects output from {\bf stdout} in the same way as
\rightang, except that it appends files instead of overwriting them.
For example, if the file called {\bf now} exists, \verb+date >>
now+ redirects the output from {\bf stdout} and adds it to the end of {\bf
now}.

\item \verb+<<+ 

Causes the command to read its input from the input of
the shell until the word following the \dblleftang symbol in the command
line is encountered. For example, \verb+cat << end+ makes {\bf
cat} read its input from the shell's input until it finds the word {\bf
end} on a line by itself.

\end{description}
\vfill
\newpage




\index{Pipes!in shell}
\index{Shell!pipes}
\index{$\mid$ pipes in shell}
\index{Pipeline separator, `;'}
\index{; pipeline separator}
\index{$\mid$ metacharacter in shell}
\index{\&\& metacharacter in shell}
\index{\& shell metacharacter}
\index{Background!tasks!in shell}
\index{Shell!background tasks}
\index{Metacharacter in shell!(}
\index{Metacharacter in shell!)}
\index{( metacharacter in shell}
\index{) metacharacter in shell}
\index{Redirection!of I/O}
\index{I/O!redirection of}
\index{Redirection!of output to file}
\index{Output!redirection of output to file}
\index{\rightang metacharacter in shell}
\index{Metacharacter in shell!\rightang}
\index{Redirection}
\index{Redirection!of input from file}
\index{Input!redirection of input from file}
\index{\leftang metacharacter in shell}
\index{Metacharacter in shell!\leftang}
\index{\dblrightang redirection of output to file}
\index{Redirection!of output to file!\dblrightang}
\index{\dblleftang metacharacters in shell}
\index{Metacharacters in shell!\dblleftang}

\subsection*{3.4 Expressions}


\begin{sloppypar}
A number of commands that are built into the shell can take
expressions as \linebreak arguments. These expressions may be constructed using
arithmetic and logical operators which are similar to those used
in the C programming language. 
In the following list the order of operator 
precedence increases from left to right,
with square brackets indicating groups of operators of equal precedence:
\end{sloppypar}
\index{Operator!operator precedence}
\index{Precedence!of arithmetic/logical operators}
\footnotesize
\begin{verbatim}
|| && | ^ & [== != =~ !~][<= >= < >][<< >>][+ -][* / %] ! ~ [( )]
\end{verbatim}
\normalsize


\index{Expressions in shell}\index{Shell!expressions in}
\index{Shell!operators (arithmetic \& logical)}\index{Operators in shell}
\index{Arithmetic operators in shell}
\index{Logical operators in shell}


In cases where operators of the same precedence occur several times, they
are evaluated left to right.
A full list of valid operators can be found in Table 3.1.
\small
\begin{table}[h]
\centering
\begin{tabular}{cl} 
\bf Operator & \bf Description\\
\\
\tt || & logical OR \\
\tt |  &  bitwise OR \\
\tt \verb+^+ & bitwise exclusive OR (XOR) \\
\tt \&\& & logical AND\\
\tt \& & bitwise AND\\
\tt == & equivalent\\
\tt != & not equivalent\\
\tt =\verb+~+ & tests for match with specified pattern\\
\tt !\verb+~+ & tests for no match with specified pattern\\
\tt ! &  logical NOT \\
\tt \verb+~+ & bitwise NOT \\
\tt <= & less than or equal to \\
\tt >= & greater than or equal to \\
\tt < & less than \\
\tt > & greater than \\
\tt \verb+>>+ & shift right \\
\tt << & shift left \\
\tt + & addition \\
\tt - & subtraction \\
\tt / & division \\
\tt * & multiplication \\
\tt \verb+%+ & modulus \\ 
\end{tabular}
\begin{center}
\normalsize
\vspace{0.25cm}

Table {\bf 3.1} Operators
\end{center}
\end{table}
\normalsize
\index{$"!\sim$ operator}
\index{Operator! $"!\sim$}
\index{$=\sim$ operator}
\index{Operator! $=\sim$}
\index{$"!=$ test for non-equivalence}
\index{Test!for non-equivalence $"!=$}
\index{$==$ test for equivalence}
\index{Test!for equivalence $==$}
\index{\& bitwise AND operator}
\index{Operator!bitwise AND $\&$}
\index{\&\& logical AND operator}
\index{Operator! logical AND $\&\&$}
\index{$\mid$ bitwise OR operator}
\index{Operator!bitwise OR $\mid$}
\index{$\mid\mid$ logical OR operator}
\index{Operator!logical OR $\mid\mid$}
\index{{\tt +} addition operator}
\index{Operator!addition {\tt +}}
\index{$\times$ multiplication operator}
\index{Operator!multiplication $\times$}
\index{"! logical NOT operator}
\index{Operator! logical NOT "!}
\index{\% modulus operator}
\index{Operator!modulus \%}
\index{/ division operator}
\index{Operator!division /}
\index{\dblleftang shift left operator}
\index{Operator!shift left \dblleftang}
\index{Shift!left operator}
\index{Shift!right operator}
\index{$\sim$ bitwise NOT operator}
\index{Operator!bitwise NOT $\sim$}
\index{\dblrightang shift right operator}
\index{Operator!shift right \dblrightang}
\index{$-$ subtraction operator}
\index{Operator!subtraction}
\index{\rightang greater than operator}
\index{Operator!greater than \rightang}
\index{\leftang less than operator}
\index{Operator!less than \leftang}
\index{\leftang= operator}
\index{\rightang= operator} 







\subsection*{3.5 Command execution}

\index{Shell!substitutions}
\index{Substitution!by shell in command line}
The shell takes input, acts upon any commands it finds and produces output.
In doing so, it may perform certain substitutions and transformations. 
These actions are listed below in the order in which they may occur.
\begin{enumerate}
\item ({\bf History substitution}.) Using previous command input to produce new input. 
\item ({\bf Alias substitution}.) Checking alternative command names for built-in commands. 
\item ({\bf Variable substitution}.) Substituting a value for a named variable. 
\item Expanding the name of a command.
\item Expanding the name of a filename given as an argument.
\end{enumerate}

Each of the actions listed is described in the sections to follow.



\subsection*{3.6 The history list and history substitution}

\index{History!list}
\index{History!substitution}\index{Substitution!history}
The Helios shell places words from previous commands into a list so that they
can be retrieved, edited and executed at a later stage. This is particularly
useful for repeating previous commands, correcting typing errors in commands
or executing commands which are similar to those which have already been used.

The Helios shell provides two levels of access to the history list. Firstly
there is an interactive history mechanism which allows the list to be accessed
and edited by using various control key combinations. The list can also be
accessed and manipulated by using  special characters which are placed in a
command line. 

\index{Interactive!use of history list}
When the shell gives a prompt, respond by entering a line
of text or use the control keys which are listed below. These
control keys allow the current command line to be overwritten with a 
previous command line from the history list. This line may then be edited
by using other control keys to position the cursor ready for text to be 
inserted or deleted. The edited command line can then be executed by 
pressing the return key. There is no need to move the cursor to the end of the line.

\begin{description}
\index{Control!keys used in shell}\index{Shell!control keys}
\index{Editing!command lines in shell}\index{Shell!editing command lines in}
\item{\bf CTRL-A} 

Moves the cursor to the start of the line.

\item{\bf CTRL-E} 

Moves the cursor to end of the line.
%This can be used repeatedly to display each line in the history list.

\item{\bf CTRL-P} 

Replaces the current line with the preceding line in the history list.
This can be used repeatedly to display each line in the list.

\item{\bf CTRL-R} 

Replaces the current line with a line from the history list which begins
with the same word as at the current cursor position. If CTRL-R is used
on a blank line, the last command is fetched from the history list.

\item{\bf CTRL-U} 

Deletes the entire line.

\item{\bf CTRL-W} 

Moves the cursor to the right by one word.

\item{\bf CTRL-X} 

Deletes the word at the cursor's current position.
\end{description}

\index{"! history substitution character}
\index{History!substitution using "!}

The shell is instructed that a history substitution is to occur in a
command line by using  the character !. This character may occur at any
point in a line and is followed by one or more qualifying characters.
When the command line is submitted for execution, the shell will attempt to
replace these characters with a word (or a group of words)
extracted from the history list. The command line is then {\bf echoed} to the 
screen and executed.

There are three types of qualifying character which can be used with !.
The first of these is a number which corresponds to the event number of
the required entry in the list. All entries in the history list are
assigned an event number by the shell, such that the first entry is numbered
1 and subsequent entries are assigned progressively larger event numbers 
(2,3,4,$...$). The character sequence !100 therefore refers to event
number 100 in the list. Similarly, if the current event number is known, an
offset can be specified instead of an absolute event number. If the current
event number is 106, !--6 will therefore refer to event 100.

The `!' character itself can also be used as a qualifying character. In
this case, whenever the shell encounters the character sequence \verb+!+\verb+!+, it
substitutes it for the last entry in the history list. A command line
consisting solely of these two characters is therefore an instruction to
the shell that it should repeat the last command.

To select a specific word from a previous command, use
the colon character. When used in conjunction with the `!' character
and an optional event number, it causes the shell to substitute
these characters for the specified sequence of words which are stored in
the history list. A full list of designators which can be used with the
colon character is given below, but as an example, 
consider the following command line:
\begin{quote}
   \tt echo !100:2
\end{quote}

This will {\bf echo} to the screen the second word from event number 100. 
\vspace{0.25cm}




\noindent {\bf Designator} \hspace{1cm} {\bf Meaning}
\vspace{0.25cm}

\begin{description}

\item {\it n} \hspace{1cm} {\it n}th argument. Argument 0 is the first (command) word.

\item \verb+^+ \hspace{1cm} The first argument (equivalent to `1').

\item \verb+$+ \hspace{1cm} The last argument.

\item \verb+*+ \hspace{1cm} All arguments. If the event relates to a single word, this 
will be null.

\item {\it n-m} \hspace{0.7cm} A range of words. For example, 0--2 means words 0 to r2.

\item {\it -m} \hspace{0.9cm} Equivalent to 0--$m$.

\item {\it n-} \hspace{1cm} All arguments from argument $n$ onwards (excluding the final word).

\item {\it n}\verb+*+ \hspace{0.9cm} All arguments from argument $n$ onwards (including the final word).

\end{description}
\index{Select!n'th argument from past event}
\index{Select!first argument from past event}
\index{Select!last argument from past event}
\index{Retrieve!all arguments from a past event}
\index{Retrieve!a range of words from a past event}

\vspace{0.25cm}

\index{{\tt\^{}}}
\index{\$}
\index{$\times$}
\index{-}
\index{{\tt\^{}} used to manipulate history list}
In addition to this, it is possible to omit the colon character whenever
the qualifying character is {\tt \verb+^+}, {\tt \$}, {\tt *} or {\tt -}.
The previous event can be recalled with one or more words changed by 
use of \verb+^+ alone. This is achieved by ensuring that \verb+^+ is the first
non-blank character on a command line. The shell then interprets all 
characters up to
the next \verb+^+ as a pattern which is to be replaced by the characters which
follow the second occurrence of \verb+^+. For example,

\begin{verbatim}
   ^helois^helios
\end{verbatim}

\noindent replaces the first occurrence of {\tt helois} in the last command with 
{\tt helios} and then executes the result. To append additional 
text to a line, 
use a third {\tt \verb+^+}, as in: 

\begin{verbatim}
   ^helois^helios^hello
\end{verbatim}


This command will substitute {\tt helois} for {\tt helios} and append {\tt hello}.
A complete or partial listing of all events currently in the history list,
with their associated event numbers, can be obtained by using
the {\bf history} command.

\subsection*{3.7 Aliases}

\index{Aliases}
After performing the history substitutions, the shell performs alias
substitutions on the command line. Aliases are alternative names which the
user may assign to almost all of the commands which are available from
within Helios. They are created by using the {\bf alias} command and
removed from the shell's list of aliases by using {\bf unalias}. For example,
\begin{quote}
   \tt alias dir ls
\end{quote}
assigns the alias {\bf dir} to {\bf ls} so that all references to the 
command {\bf dir} will now be treated as an invocation of {\bf ls}. Similarly,
\begin{quote}
   \tt unalias dir
\end{quote}
causes the shell to forget the alias.

\index{History!within alias definition}

When substituting a command name for an alias, the Helios shell allows the
full facilities of the history mechanism to be employed. Furthermore, since
the shell adds a command line to its history list before it performs
alias substitution, all references to the previous command actually refer
to the current command before alias substitution was performed. 
For example, consider the case where {\bf echo2} had been defined as an alias:

\begin{verbatim}
    alias echo2 `echo \!:2'
\end{verbatim}

\noindent meaning that {\bf echo2} has become an alias for the command which {\bf echoes} the
second argument of the previous command to the screen. (The quotes are needed
to ensure that {\bf echo} and its argument are treated as one word and the `\verb+\+'
before the `!' character is needed to prevent the shell from performing
the history substitution at the time the alias is defined.) Type:
\begin{quote}
   \tt echo2 one two three
\end{quote}
and the shell will enter the command into the history list and substitute
{\bf echo2} and its arguments for the aliased command. History substitution will
then be reapplied to the resulting command line, so that the
command actually executed is as follows:
\begin{quote}
   \tt echo two
\end{quote}


In cases where the alias does not make use of the history facilities, only
the command name is substituted. The arguments are left unchanged. As an
example, consider the following:

\begin{verbatim}
   alias dir ls
   dir /helios
\end{verbatim}

\noindent which is equivalent to:

\begin{quote}
   \tt ls /helios
\end{quote}


\subsection*{3.8 Variables and variable substitution}

\index{Environment variables}\index{Variables!environment}
When the shell is executed, it receives a
list of variables from the operating system, and these provide the shell with 
information about the 
environment in which it is running. These environment variables are then
copied into the shell's own variables and are passed on to any program
that is executed from within the shell. These variables are listed below.
\vspace{0.25cm}


\begin{table}[h]
\begin{tabular}{ll}
\bf HOME & The user's home directory.\\
\\
\bf USER & The user's login name.\\
\\
\bf PATH & The list of directories which are searched when a command is\\
& executed.\\
\\
\bf TERM & The terminal type.\\
\\
\bf SHELL & The full pathname for the shell.\\
\\
\bf EDITOR & The editor to be used.\\
\end{tabular}
\end{table}

%\begin{description}

%\item{\bf HOME}

%The user's home directory.

%\item{\bf USER}

%The user's login name.

%\item{\bf PATH}

%The list of directories searched when a command is executed.

%\item{\bf TERM}

%The terminal type.

%\item{\bf SHELL}

%The full pathname for the shell.

%\item{\bf EDITOR}

%The editor to be used.

%\end{description}

\index{Shell@{\bf shell} - environment variable}
\index{Environment variable!shell@{\bf shell}}
\index{USER - environment variable}
\index{Environment variable!USER}
\index{TERM!environment variable}
\index{Environment variable!TERM}
\index{PATH - environment variable}
\index{Environment variable!PATH}
\index{HOME - environment variable}
\index{Environment variable!HOME}
\index{EDITOR - environment variable} 
\index{Environment variable!EDITOR}


When the shell variables {\bf user}, {\bf term}, {\bf home} and {\bf path} are changed,
the shell changes the corresponding environment variables {\bf USER}, 
{\bf TERM}, {\bf HOME} and {\bf PATH} to reflect that change. 
The shell also provides 
two commands for manipulating these and the other environment variables
directly. These commands are described below.
\begin{quote}
\index{setenv@{\bf setenv} - shell command}
\index{Shell command!setenv@{\bf setenv}} {\tt setenv} {\it name value}
\end{quote}

Sets the named environment variable to the value of the string value.
\begin{quote}
\index{unsetenv@{\bf unsetenv} - shell command}
\index{Shell command!unsetenv@{\bf unsetenv}}
   \tt unsetenv {\it pattern}
\end{quote}

Unsets all environment variables with names which match the pattern.
\begin{quote}
\index{printenv@{\bf printenv} - shell command}
\index{Shell command!printenv@{\bf printenv}}
   \tt printenv 
\end{quote}

Lists the environment variables and their values.

\subsubsection*{3.8.1 Shell variables}

\index{Shell!variables}
\index{Variables in shell}
The Helios shell maintains a list of internal variables which can have one
or more words as a value. Some of these variables are maintained directly
by the shell, but others can be created or destroyed by the user. The value
of any of these variables can be included in a command line at any point.
The shell then uses variable substitution to substitute the variable's
name for its value.
The variables listed below are
predefined and have special meaning to the shell. 
\vspace{0.25cm}
%\begin{sloppypar}
\begin{description}

\index{argv@{\bf argv}! - shell variable}
\index{Shell variable!argv@{\bf argv}}
\item {\bf argv} 

The arguments of the command line which was used to invoke the shell,
where the first argument is {\it \$argv[1]}.

\index{cdpath@{\bf cdpath} - shell variable}
\index{Shell variable!cdpath@{\bf cdpath}}
\item {\bf cdpath} 

Used to specify a list of directories which are used by {\bf cd}
when it is searching for a subdirectory.

\index{cwd@{\bf cwd} - shell variable}
\index{Shell variable!cwd@{\bf cwd}}
\item {\bf cwd} 

The full path name of the current directory.
\index{echo@{\bf echo} - shell variable}
\index{Shell variable!echo@{\bf echo}}

\item {\bf echo} 

When set, this will instruct the shell to {\bf echo} all commands on
the standard output device before they are executed.

\index{history@{\bf history} - shell variable}
\index{Shell variable!history@{\bf history}}
\item {\bf history} 

The number of commands remembered in the history list. The
last command to be executed is always remembered by the shell, regardless
of the setting of this variable.
Note that large history lists may result in the shell running out of memory. 

\index{home@{\bf home} - shell variable}
\index{Shell variable!home@{\bf home}}
\item {\bf home} 

The home directory. The filename expansion of 
\verb+~+ is the value of
this variable. {\bf cd} without any argument will arrive  in this
directory.

\index{ignoreof@{\bf ignoreeof} - shell variable}
\index{Shell variable!ignoreof@{\bf ignoreeof}}
\item {\bf ignoreeof} 

If set, this variable instructs the shell to ignore the end-of-file
characters \linebreak (CTRL-D) which would otherwise terminate the shell.

\index{noclobber@{\bf noclobber} - shell variable}
\index{Shell variable!noclobber@{\bf noclobber}}
\item {\bf noclobber} 

If set, this variable acts as a safeguard during redirection
of input and output. It instructs the shell to prevent files from being
overwritten by \rightang and ensures that a file is already present before it
is used with  \dblrightang. Suitable error messages are generated if these 
conditions are not satisfied.

\index{noglob@{\bf noglob} - shell variable}
\index{Shell variable!noglob@{\bf noglob}}
\item {\bf noglob} 

If set, this variable prevents the shell from performing filename
expansions specified by metacharacters such as {\verb+*+}.

\index{nonomatch@{\bf nonomatch} - shell variable}
\index{Shell variable!nonomatch@{\bf nonomatch}}
\item {\bf nonomatch} 

If set, this variable will prevent the shell from generating an
error when a filename expansion fails to match with a file. In these
circumstances, the unexpanded pattern is passed on to the command. Note 
that this variable does not affect the error reporting for badly formed patterns.

\index{path@{\bf path} - shell variable}
\index{Shell variable!path@{\bf path}}
\item {\bf path} 

Each word of the {\bf path} variable specifies a directory
in which commands are to be sought for execution. An empty list is assumed to
refer to the current directory only. If this variable is not set, 
commands will only be executed if their full pathname is specified.

\index{prompt@{\bf prompt} - shell variable}
\index{Shell variable!prompt@{\bf prompt}}
\item {\bf prompt} 

%\begin{sloppypar}
The value of this variable is used as the prompt sign by the shell.
For example, the command {\tt set~prompt="\$~"}
sets the prompt to the two-character string `\$~'. Two special 
characters may be used in the prompt string. The character `!' is expanded
to the current history event number; the character `?' is expanded to
the current window name used by the shell. This is useful when running
multiple shells through the {\bf wsh} command on a machine without a graphics
screen.
%\end{sloppypar}
\index{status@{\bf status} - shell variable}
\index{Shell variable!status@{\bf status}}
\item {\bf status} 

The value of this variable is maintained by the shell and will
always represent the exit code which was returned by the previous command. A
non-zero value shows that the command failed; 0 shows that it 
terminated correctly.

\index{verbose@{\bf verbose} - shell variable}
\index{Shell variable!verbose@{\bf verbose}}
\item {\bf verbose} 

If set, this variable causes the shell to {\bf echo} each word of a
command line to the standard output device immediately after it has been
history-substituted.

\end{description}
%\end{sloppypar}



\subsubsection*{3.8.2 Assigning values to shell variables}

\index{Shell!variables!assignment to}
\index{Assignments! to shell variables}
To assign a value to a shell variable,  use the {\bf set} command. This
command can be used to create and initialise a new variable or to
assign a new value to an existing variable. It can also be used to display
the current values of all variables:
\vspace{0.25cm}

\begin{description}
\item {\bf set} 

displays all variables and their values.

\item {\bf set} {\it name}

sets {\it name} to equal a single word of length {\it 0} (a null word).

\item {\verb+set+} {\it name} {\verb+=+}{\it value}

assigns the string {\it value} to the variable {\it name}.
\end{description}
\index{set@{\bf set} - shell command}
\index{Shell command!set@{\bf set}}
\vspace{0.25cm}


Note that the {\it value} of a variable can be any sequence of characters
delimited by white space. If white space is required to 
form part of the value,
quotes must enclose the sequence of characters. This is illustrated 
below.
\vspace{0.25cm}


\index{prompt@{\bf prompt} - shell variable}
\index{Shell variable!prompt@{\bf prompt}}
\index{Prompt!changing}
\index{Prompt!setting}
\index{Setting the shell's prompt}
\index{Changing!the shell's prompt}
\begin{description}
\item {\it set prompt=\$} 

sets prompt to \$.

\item {\it set prompt="\$ "} 

sets prompt to \$ .

\end{description}
\vspace{0.25cm}

The variables can also be assigned a list of values, by enclosing the
entire group of value strings in brackets. The following assignment can
therefore
be used to assign the three values: {\bf hello}, {\bf hello there} and 
{\bf world}:
\begin{quote}
   \tt set strings=(hello "hello there" world)
\end{quote}

\subsubsection*{3.8.3 Variable substitution}

\index{Variable substitution}

\begin{sloppypar}
The value of a shell variable can be substituted into a command line at 
any point by using the character \$ followed by the variable's name. 
If the variable's name consists of more than one character and it is
not delimited by white space, the name should be enclosed in braces 
\{\}. The braces can be used in other circumstances, but they are not 
strictly necessary.
If the variable {\bf path} is assigned the value {\tt /helios/bin/}, 
these command lines have the following meanings:
\end{sloppypar}

\begin{verbatim}
   $path                  = /helios/bin/
   ${path}command         = /helios/bin/command
   hello${path}command    = hello/helios/bin/command
\end{verbatim}


\begin{sloppypar}
If a variable has been assigned a list of values,  any
one of those values can be selected by using an index with the name of the
variable.
If {\bf path} is assigned three values ({\tt /helios},  {\tt /helios/bin}
and {\tt /helios/bin/cmds}), these command lines have the following meanings:
\end{sloppypar}


\begin{verbatim}
$path               
= /helios /helios/bin /helios/bin/cmds

$path[0]            
= not valid - shell generates error message

$path[1]            
= /helios

$path[3]            
= /helios/bin/cmds

$path[4]            
= not valid - shell generates error message

hello${path[2]}world
= hello/helios/binworld
\end{verbatim}


Other character sequences in the command lines can also be used to access
\index{Accessing variables}
a variable or to obtain information about its current status: 


%\begin{quote}
%     \tt \$\#{\it name}\\
%     \tt \$\{\#{\it name}\}\\
%\end{quote}
\vspace{0.25cm}

\indent \verb+$#+{\it name}
\indent \verb+$+\{\verb+#+{\it name}\}
\vspace{0.25cm}

This character sequence is replaced by the number of words that are
assigned to the variable {\bf name}. If
{\bf path} has been assigned the three values given earlier, {\tt echo~\$\#path}
will {\bf echo} 3 to the screen.
When the shell is taking its input from a file (instead of from the terminal), 
the character sequence
%\begin{quote}
%     \tt \$0
%\end {quote}

\begin{verbatim}
      $0
\end{verbatim}

\noindent will be replaced by the name of that file. If
the input is not being taken from a file, an error will be 
generated. (See also {\tt \$?0}.)
The sequence
%\begin{quote}
%     \tt \${\it number}\\
%     \tt \$\{{\it number}\}\\
%\end{quote}
\vspace{0.25cm}

\indent \verb+$+{\it number}

\indent \verb+$+\{{\it number}\}
\vspace{0.25cm}

\noindent is equivalent to {\tt \$argv[} {\it number} {\tt]}.
This character sequence can be used to determine if a variable has been set:
%\begin{quote}
%   \tt \$?{\it name}\\
%   \tt \$?\{{\it name}\}\\
%\end{quote}
\vspace{0.25cm}

\indent \verb+$?+{\it name}

\indent \verb+$?+\{{\it name}\}
\vspace{0.25cm}

If the variable has been set, the sequence is replaced by 1; otherwise,
it is replaced by 0.
This character sequence can be used to determine if the shell is taking its
input from a file: 
\begin{quote}
   \tt \$?0
\end{quote}


If a file is being used, the character sequence is
replaced by 1; otherwise, it is replaced by 0.
(See also the entry for {\tt \$0}.) 
The following character sequence 
will be substituted by words read from the
standard input device: 
\begin{quote}
   \tt \$<
\end{quote}

This sequence is particularly useful for obtaining
keyboard input from within a shell script.
A command line containing shell variables is entered
into the history list in its expanded form. Multiple variable
substitutions in a single line are allowed, but recursive substitutions
are not supported.

\subsection*{3.9 Redirection}

\index{Redirection!of I/O}
\index{I/O!redirection of}
Any command which communicates with the user by means of the standard input
and output devices can be made to communicate with files instead. This can
be achieved by using metacharacters in a command line and it is particularly
useful for sending large amounts of output to a file for casual viewing
with a text editor. The metacharacters and their filename arguments can
usually be placed anywhere on a command line.
\begin{quote}
  \tt < {\it name}
\end{quote}
\index{\leftang redirection of I/O}
\index{Redirection!of I/O!\leftang}

This redirects input to come from the file {\bf filename}, instead of from
{\bf stdin}.
The filename will be subjected to variable, alias and wildcard substitution.
For example,

\begin{verbatim}
    cat < /helios/example/hello.c
\end{verbatim}
causes {\bf cat} to read its input from hello.c instead of from the keyboard,
\index{\dblleftang redirection of I/O}
\index{Redirection!of I/O!\dblleftang}
\begin{verbatim}
    cat << word
\end{verbatim}
takes input from the standard input device, {\bf stdin}, until the word
({\bf word}) is encountered. 
For example,

\begin{verbatim}
    cat << end
\end{verbatim}
causes {\bf cat} to take its input from the keyboard and to interpret
the first occurrence of {\bf end} as the end of input.
\vspace{0.25cm}

\rightang{\it filename} \hspace{0.25cm} \rightang!{\it filename} \hspace{0.25cm}
\rightang\&{\it filename} \hspace{0.25cm} \rightang\&!{\it filename}
\vspace{0.25cm}


\index{\rightang redirection of I/O}
\index{Redirection!of I/O!\rightang}
\index{\rightang\& redirection of I/O}
\index{Redirection! of I/O!\rightang\&}
\begin{sloppypar}
These redirect output to the named file. Those metacharacter sequences which 
do not include the ampersand character redirect output that would otherwise
be sent to the standard output device, {\bf stdout}; those which include the
ampersand character redirect the standard error output, {\bf stderr}. If the
named file does not exist, it is created. If it does exist it 
is overwritten. By setting the shell variable {\bf noclobber}, 
the shell is
prevented from overwriting a file. The {\tt !} character overrides
the effects of {\bf noclobber}. The filename is subjected to variable,
alias and wildcard substitution. For example,
\end{sloppypar}

\begin{verbatim}
   cc -o outfile infile >& errors
\end{verbatim}


The file {\bf errors} now contains the compiler's error messages. If the error
messages relate to a file, {\bf emacs} could be used to display these messages
and to edit the file simultaneously by using the editor's windowing facilities.
\vspace{0.25cm}

\dblrightang{\it filename} \hspace{0.25cm} \dblrightang\&{\it filename} 
\hspace{0.25cm} \dblrightang!{\it filename} \hspace{0.25cm} \dblrightang\&!{\it filename}
\vspace{0.25cm}

\index{\dblrightang redirection of I/O}
\index{\dblrightang\& redirection of I/O}
\index{Redirection!of I/O!\dblrightang\&}
\index{Redirection!of I/O!\dblrightang}

The above redirect output and append it to the named file. These metacharacter
sequences are similar to those constructed from a single \rightang 
character, but
they append output to the named file instead of overwriting its current contents.
If the shell variable {\bf noclobber} is set, an error is generated
if the file does not exist. This error can be suppressed by using the
metacharacter sequences which use {\tt !}.

\subsection*{3.10 Control flow}

\index{Flow-control commands}
A number of the shell's built-in commands are for specifying the order in 
which commands are executed. These commands are similar to the control flow
commands which occur in many high-level programming languages, such as C.
They are normally used in shell scripts, but they can be entered from a terminal.
If a terminal is used, the commands following the control flow constructs may 
or may not be executed when they are entered. If the shell will not execute
the next command, the prompt will be changed to a question mark (?).
\vfill
\newpage

\subsubsection*{3.10.1 if-then-else}

\index{if-then-else@{\bf if-then-else} construct in shell}
This sequence of commands can be used to select a group of commands for execution.
The syntax for this construct is as follows:
\begin{tabbing}
   \= {\tt if} \= {\tt (} {\it expression} {\tt ) then}\\
  \> \> {\it command}\\
  \> \> {\it \ldots\ } \\
  \> \> {\it command}\\
\> {\tt else}\\
  \> \> {\it command}\\
  \> \> {\it \ldots\ } \\
  \> \> {\it command}\\
\> {\tt endif}
\end{tabbing}
\index{endif@{\bf endif} - shell command}
\index{Shell command!endif@{\bf endif}}

 If {\it expression} evaluates to any non-zero value,  all commands up to
the following {\bf else} or {\bf endif} commands will be executed. 
If the expression evaluates to zero, all commands between {\bf else} and
{\bf endif} will be executed. None of the commands in this construct can
be pipelines or lists of commands separated by a semi-colon. If nested 
if-then-else constructs are used, only one {\bf endif} is needed as a terminator:

\begin{verbatim}
   if ($term == "ibm") then
         echo This is an IBM
      else
         echo This is not an IBM
   endif
\end{verbatim}


\subsubsection*{3.10.2 switch}

\index{switch@{\bf switch} - shell command}
\index{Shell command!switch@{\bf switch}}
This construct can be used to select one of many commands for execution.
The syntax is as follows:

\begin{tabbing}
   \= {\tt switch} \= {\tt (}{\it string}{\tt )}\\
\> {\tt case} {\tt<}{\it string-1}{\tt >}:\\
\> \> {\it command}\\
\> \> {\it \ldots\ }\\
\> \> {\it command}\\
\> {\tt breaksw}
\> {\it \ldots\ }\\
\> {\tt case} {\tt<}{\it string-n}{\tt >}:\\
\> \> {\it command}\\
\> \> {\it \ldots\ }\\
\> \> {\it command}\\
\> {\tt breaksw}\\
\> {\tt default:}\\
\> \> {\it command}\\
\> \> {\it \ldots\ }\\
\> \> {\it command}\\
\> {\tt breaksw}\\
\> {\tt endsw}\\
\end{tabbing}
\index{case@{\bf case} - shell command}
\index{Shell command!case@{\bf case}}
\index{breaksw@{\bf breaksw} - shell command}
\index{Shell command!breaksw@{\bf breaksw}}
\index{default@{\bf default} - shell command}
\index{Shell command!default@{\bf default}}
\index{endsw@{\bf endsw} - shell command}
\index{Shell command!endsw@{\bf endsw}}
\begin{sloppypar}
 The construct allows a unique label (case prefix) to be applied to each
group of commands so that the group is only executed if the label matches
the string. If none of the case labels match with the argument string, 
the commands following the optional default label will be executed. The 
argument string will be subjected to both variable and wildcard expansion,
but if wildcards are used and the pattern matches with more than one file,
an error is generated. The case labels may also contain wildcards and
shell variables, but wildcards in this context will be tested for a match 
with the argument string and not with filenames. For example:
\end{sloppypar}

\begin{verbatim}
   switch (hello)
      case hi:
         echo this should not appear
      breaksw
      case *llo:
         echo this should appear
      breaksw
   endsw
\end{verbatim}


\subsubsection*{3.10.3 while}

\index{while@{\bf while} - shell command}
\index{Shell command!while@{\bf while}}
This construct is used to repeat a group of commands while the specified
expression evaluates to zero. The syntax for this construct is as follows:

\begin{tabbing}
   \= {\tt while} \= ({\it expression})\\
 \> \> {\it command-1}\\
 \> \> {\it \ldots}\\
 \> \> {\it command-n}\\
 \> {\tt end}
\end{tabbing}

\index{end@{\bf end} - shell command}
\index{Shell command!end@{\bf end}}

 Consider the following as an example of its use:

\begin{verbatim}
   set i=10
      while ($i != 0)
      @i = $i - 1
      echo Current value of i is $i
   end
\end{verbatim}


\subsubsection*{3.10.4 foreach}

\index{foreach@{\bf foreach} - shell command}
\index{Shell command!foreach@{\bf foreach}}
This command  assigns a series of values to a shell variable and
executes a sequence of commands between each new assignment. The syntax for 
this construct is as follows:
\begin{tabbing}
   \= {\tt foreach} \= {\it name} ({\it wordlist})\\
\> \> {\it command-1}\\
\> \> {\it \ldots}\\
\> \> {\it command-n}\\
\> {\tt end}
\end{tabbing}
\index{end@{\bf end} - shell command}
\index{Shell command!end@{\bf end}}
As an example of its use, consider the following:

\begin{verbatim}
   foreach person (andy alan paul tim)
      echo $person
   end
\end{verbatim}
where each of the four names is written to the standard output device.
\printindex
\end{document}


