TSH(1) | General Commands Manual | TSH(1) |
The options are as follows:
The shell may also be invoked non-interactively to read, interpret, and execute an ASCII command file. The specified file and any arguments are treated as positional parameters (see Parameter substitution below) during execution of the command file.
Otherwise, if no arguments are specified and if both the standard input and standard error are connected to a terminal, the shell is interactive. An interactive shell prompts a regular user with a `% ' or with a `# ' for the superuser before reading each command line from the terminal.
When such a character is unquoted, it has special meaning to the shell. The shell uses it to separate words (see Commands and Command lines below). A quoting metacharacter is any one of the following:
See Quoting below. The substitution metacharacter is a:
See Parameter substitution below. Finally, a pattern metacharacter is any one of the following:
See File name generation below.
If the first argument names a special command, the shell executes it (see Special commands below). Otherwise, the shell treats it as an external utility or command, which is located as follows.
(+) tsh expects to find its external utilities (glob, if, goto, and fd2) in the /usr/local/libexec/etsh-5.4.0/tsh directory, not by searching the environment variable PATH. Notice that these external utilities are special to the shell and are required for full functionality.
(+) Otherwise, if the command name contains no `/' characters, the sequence of directories in the environment variable PATH is searched for the first occurrence of an executable file by that name, which the shell attempts to execute. However, if the command name contains one or more `/' characters, the shell attempts to execute it without performing any PATH search.
(+) If an executable file does not begin with the proper magic number or a `#!shell' sequence, it is assumed to be an ASCII command file, and a new shell is automatically invoked to execute it. The environment variable EXECSHELL specifies the shell which is invoked to execute such a file.
If a command cannot be found or executed, a diagnostic is printed.
A command line, or list, consists of one or more pipelines separated, and perhaps terminated by ; or &. The semicolon designates sequential execution. The ampersand designates asynchronous execution, which causes the preceding pipeline to be executed without waiting for it to finish. The process ID of each command in such a pipeline is reported, so that it may be used if necessary for a subsequent kill(1).
A list contained within parentheses such as ( list ) is executed in a subshell and may appear in place of a simple command as a filter.
If a command line is syntactically incorrect, a diagnostic is printed.
Hangup Quit Illegal instruction Trace/BPT trap IOT trap EMT trap Floating exception Killed Bus error Memory fault Bad system call Broken pipe
For an asynchronous process, its process ID is prepended to the appropriate message. If a core image is produced, ` -- Core dumped' is appended to the appropriate message.
A redirection of the form <arg causes the file arg to be used as the standard input (file descriptor 0) for the associated command.
A redirection of the form >arg causes the file arg to be used as the standard output (file descriptor 1) for the associated command. If arg does not already exist, it is created; otherwise, it is truncated at the outset.
A redirection of the form >>arg is the same as >arg, except if arg already exists the command output is always appended to the end of the file.
For example, either of the following command lines:
% date >index.txt ; pwd >>index.txt ; ls -l >>index.txt % ( date ; pwd ; ls -l ) >index.txt
creates on the file `index.txt', the current date and time, followed by the name and a long listing of the current working directory.
A >arg or >>arg redirection associated with any but the last command of a pipeline is ineffectual, as is a <arg redirection with any but the first.
The standard error (file descriptor 2) is never subject to redirection by the shell itself. Thus, commands may write diagnostics to a location where they have a chance to be seen. However, fd2(1) provides a way to redirect the diagnostic output to another location.
If the file for a redirection cannot be opened or created, a diagnostic is printed.
Individual characters, and sequences of characters, are quoted when enclosed by a matched pair of double (") or single (') quotes. For example:
% awk '{ print NR "\t" $0 }' README ^ more
causes awk(1) to write each line from the `README' file, preceded by its line number and a tab, to the standard output which is piped to more(1) for viewing. The outer single quotes prevent the shell from trying to interpret any part of the string, which is then passed as a single argument to awk.
An individual backslash (\) quotes, or escapes, the next individual character. A backslash followed by a newline is a special case which allows continuation of command-line input onto the next line. Each backslash-newline sequence in the input is translated into a blank.
If a double or single quote appears but is not part of a matched pair, a diagnostic is printed.
tsh name [arg1 ...]
If the first character of name is not -, it is taken as the name of an ASCII command file, or shell script, which is opened as the standard input for a new shell instance. Thus, the new shell reads and interprets command lines from the named file.
Otherwise, name is taken as one of the shell options, and a new shell instance is invoked to read and interpret command lines from its standard input. However, notice that the -c option followed by a string is the one case where the shell does not read and interpret command lines from its standard input. Instead, the string itself is taken as a command line and executed.
In each command line, an unquoted character sequence of the form $N, where N is a digit, is treated as a positional parameter by the shell. Each occurrence of a positional parameter in the command line is substituted with the value of the Nth argument to the invocation of the shell (argN). $0 is substituted with name.
In both interactive and non-interactive shells, $$ is substituted with the process ID of the current shell. The value is represented as a 5-digit ASCII string, padded on the left with zeros when the process ID is less than 10000.
All substitution on a command line is performed before the line is interpreted. Thus, no action which alters the value of any parameter can have any effect on a reference to that parameter occurring on the same line.
A positional-parameter value may contain any number of metacharacters. Each one which is unquoted, or unescaped, within a positional-parameter value retains its special meaning when the value is substituted in a command line by the invoked shell.
Take the following two shell invocations for example:
% tsh -c '$1' 'echo Hello World! >/dev/null' % tsh -c '$1' 'echo Hello World! \>/dev/null' Hello World! >/dev/null
In the first invocation, the > in the value substituted by $1 retains its special meaning. This causes all output from echo(1) to be redirected to /dev/null. However, in the second invocation, the meaning of > is escaped by \ in the value substituted by $1. This causes the shell to pass `>/dev/null' as a single argument to echo instead of interpreting it as a redirection.
The meaning of each pattern character is as follows:
Any other character in a pattern matches itself in a file name.
Notice that the `.' character at the beginning of a file name, or immediately following a `/', is always special in that it must be matched explicitly. The same is true of the `/' character itself.
If the pattern contains no `/' characters, the current directory is always used. Otherwise, the specified directory is the one obtained by taking the pattern up to the last `/' before the first unquoted *, ?, or [. The matching process matches the remainder of the pattern after this `/' against the files in the specified directory.
In any event, a list of file names is obtained from the current (or specified) directory which match the given pattern. This list is sorted in ascending ASCII order, and the new sequence of arguments replaces the given pattern. The same process is carried out for each of the given pattern arguments; the resulting lists are not merged. Finally, the shell attempts to execute the command with the resulting argument list.
If a pattern argument refers to a directory which cannot be opened, a `No directory' diagnostic is printed.
If a command has only one pattern argument, a `No match' diagnostic is printed if it fails to match any files. However, if a command has more than one pattern argument, a diagnostic is printed only when they all fail to match any files. Otherwise, each pattern argument failing to match any files is removed from the argument list.
If SIGINT, SIGQUIT, or SIGTERM is already ignored when the shell starts, it is also ignored by the current shell and all of its child processes. Otherwise, SIGINT and SIGQUIT are reset to the default action for sequential child processes, whereas SIGTERM is reset to the default action for all child processes.
For any signal not mentioned above, the shell inherits the signal action (default or ignore) from its parent process and passes it to its child processes.
Asynchronous child processes always ignore both SIGINT and SIGQUIT. Also, if such a process has not redirected its input with a <, |, or ^, the shell automatically redirects it to come from /dev/null.
However, if the shell is interactive and detects an error, it exits with a non-zero status if the user types an EOT at the next prompt.
Otherwise, if the shell is non-interactive and is reading commands from a file, any shell-detected error causes the shell to cease execution of that file. This results in a non-zero exit status.
A non-zero exit status returned by the shell itself is always one of the values described in the following list, each of which may be accompanied by an appropriate diagnostic:
Etsh home page: https://etsh.nl/
`The UNIX Time-Sharing System' (CACM, July, 1974):
https://etsh.nl/history/unix/
gives the theory of operation of both the system and the shell.
The Thompson shell was used as the standard command interpreter through Version 6 (V6) UNIX. Then, in Version 7 (V7) UNIX, it was replaced by the Bourne shell. However, the Thompson shell was still distributed with the system as osh because of known portability problems with the Bourne shell's memory management in Version 7 (V7) UNIX.
Tsh has no facilities for setting, unsetting, or otherwise manipulating environment variables within the shell. This must be accomplished by using other tools such as env(1).
Like the original, tsh is not 8-bit clean as it uses the high-order bit of characters for quoting. Thus, the only complete character set it can handle is 7-bit ASCII.
Notice that certain shell oddities were historically undocumented in this manual page. Particularly noteworthy is the fact that there is no such thing as a usage error. Thus, the following shell invocations are perfectly valid:
tsh -cats_are_nice!!! ': "Good kitty =)"' tsh -tabbies_are_too! tsh -s
The first two cases correspond to the -c and -t options respectively; the third case corresponds to the - option.
Set-ID execution denied
If the shell did support set-ID execution, it could possibly allow a user to violate the security policy on a host where the shell is used. For example, if the shell were running a setuid-root command file, a regular user could possibly invoke an interactive root shell as a result.
This is not a bug. It is simply how the shell works. Thus, tsh does not support set-ID execution. This is a proactive measure to avoid problems, nothing more.
March 28, 2019 | etsh-5.4.0 |