home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / SHELLS / sh73.lzh / DOC / sh.doc < prev    next >
Text File  |  1998-05-26  |  86KB  |  2,059 lines

  1. An sh-like shell for OS-9
  2.  
  3.  
  4. Version 2.1, edition 73, last revision on May 27, 1998
  5.  
  6.  
  7. 1.     Origin, support, no warranty
  8. -----------------------------------
  9.  
  10. This program is based on the shell that was part of the initial release of
  11. Andrew S. Tannenbaum's MINIX. It has been adapted to OS-9 through a number of
  12. contributions of OS-9 enthusiasts, mostly by Reimer Mellin and released as
  13. part of the TOP software package. In 1992, a user's manual was written by
  14. Carsten Emde who also started a changelog protocol and continued development
  15. and maintenance of the 'sh' sources. From this time onwards, 'sh' is available
  16. as EFFO (European Forum For OS-9) PD disk. Since then, after more than 2000
  17. hours of programming and testing, 'sh' became nearly 100% compatible with the
  18. standard OS-9 shell and the Bourne shell; in addition, it now offers a large
  19. part of the functionality contained in UNIX shells such as 'csh' and 'bash'.
  20. Since 1994, 'sh for OS-9' is part of the OS-9 release of reccoware's MGR
  21. graphical window system and in June 1997, 'sh' was first uploaded to
  22. ftp://os9archive.rtsi.com. A limited support and, possibly, bug fixing
  23. are offered (but not guaranteed) via E-Mail (carsten@ceag.ch).
  24.  
  25. Because the program is licensed free of charge, there is no warranty for the
  26. program, to the extent permitted by applicable law. Except when otherwise
  27. stated in writing the copyright holders and/or other parties provide the
  28. program "as is" without warranty of any kind, either expressed or implied,
  29. including, but not limited to, the implied warranties of merchantability and
  30. fitness for a particular purpose. The entire risk as to the quality and
  31. performance of the program is with you. Should the program prove defective,
  32. you assume the cost of all necessary servicing, repair or correction.
  33.  
  34. In no event unless required by applicable law or agreed to in writing will any
  35. copyright holder, or any other party who may modify and/or redistribute the
  36. program as permitted above, be liable to you for damages, including any
  37. general, special, incidental or consequential damages arising out of the use
  38. or inability to use the program (including but not limited to loss of data or
  39. data being rendered inaccurate or losses sustained by you or third parties or
  40. a failure of the program to operate with any other programs), even if such
  41. holder or other party has been advised of the possibility of such damages.
  42.  
  43.  
  44.  
  45. 2.     Introduction
  46. -------------------
  47.  
  48. The 'sh' shell program was intended as a surrogate for Mware's shell. Maximum
  49. attention was, therefore, drawn to offer the basic functionality of the Mware
  50. shell and also of the Bourne shell in order to allow using both OS-9 and UNIX
  51. shell scripts. In addition, useful features of the 'csh' and the 'bash' shell
  52. have been integrated. Compatibility of these four sources was, however, not
  53. always possible: the Bourne shell standard output append symbol ('>>'), for
  54. example, is the standard error redirection symbol of the Mware shell. In
  55. addition, command line editing using uEmacs commands was not always compatible
  56. to the SCF line editing commands of the Mware shell: the Mware shell's redraw
  57. current line command (Ctrl-A) sets the uEmacs cursor to the beginning of a
  58. line. As a general programming rule, compatibility to 'bash' was given the
  59. highest priority followed by compatibility to 'shell'. There are, however, much
  60. more compatibilities than incompatibilities; normally, it does not take more
  61. than a day or two to become familiar with 'sh' for OS-9.
  62.  
  63.  
  64.  
  65. 3.     Getting started
  66. ----------------------
  67.  
  68. 3.1.   Installation
  69. The 'sh' program is located in the CMDS directory of the distribution disk.
  70. It does not require other modules such as trap handlers to run. It should
  71. be copied to the system's standard execution directory in such a way that it
  72. can be started by typing the
  73.  
  74.        $ sh
  75.  
  76. command. Normally, however, 'sh' is started directly from the login procedure
  77. that is defined in the password file. A typical entry in the password file
  78. could have the following definitions:
  79.  
  80.        name,*PASSWD*,<gid>.<uid>,<prio>,.,/dd,sh -ep="<$HOST/$USER/sh@>$CWD:"
  81.  
  82. It may also be a good idea to copy the suggested profile file that is
  83. named 'dot.profile' from the SYS directory to the user's home directory:
  84.  
  85.        $ copy /d0/SYS/dot.profile ~/.profile
  86.  
  87. This script contains a number of useful settings. There is also an
  88. example login file called 'dot.login' but this file should better not be
  89. copied to '~/.login' but only be used as an example, since many settings
  90. are system-specific. The file '.login' in the user's home directory is
  91. only executed by the login shell, i.e. the shell that has been forked by
  92. the 'login' program. There is also a way to make system-wide default
  93. definitions by creating the file '/dd/SYS/profile'. Settings in this
  94. file are evaluated first so that they may be overwritten by alternative
  95. settings in a particular user's '~/.profile' file. Subsequently started
  96. 'sh' tasks for script file execution do not read '~/.profile', they only
  97. evaluate '/dd/SYS/profile'. Therefore, the latter must not include
  98. functions, grave construct, read commands or similar; it is merely
  99. intended for alias and environment settings that are user-independent.
  100. When 'sh' exits from a regular interactive session the files '.logout'
  101. and '/dd/SYS/sh.logout' are executed, if available.  The contained
  102. commands of all named procedures are executed in the same way as if they
  103. had been entered manually. The '-r' command line option can be set to
  104. completely disable processing of all named profile files including
  105. '~/.login' etc. If a user-defined profile file is specified using the
  106. '-f=<profile>' command line option, this file is evaluated last.
  107.  
  108.  
  109. 3.2.   Supplementary programs
  110. In addition, the distribution disk contains the following binary programs that
  111. may be required to run UNIX scripts under OS-9:
  112.  
  113.        Name       Function
  114.        basename   Transform a fully-qualified file name into the name of its
  115.                   last element and, optionally, omit suffix
  116.        dirname    Transform a fully-qualified file name into the name of its
  117.                   directory
  118.        cat        Same as merge, needed for the creation of here files
  119.        strcmp     Extended string comparisons
  120.  
  121. The programs basename, dirname and strcmp kindly have been contributed by
  122. M.C. Gregorie.
  123.  
  124.  
  125. 3.3.   Example scripts
  126. Finally, the distribution disk contains a directory SCRIPTS where a number
  127. of 'sh' scripts can be found. They are mainly intended as examples and for
  128. test purposes but some of them may also be copied into the system's
  129. standard execution directory and used as if they were regular programs:
  130.  
  131.        Name       Function
  132.        find       Find a file in the directory tree
  133.        which      Search for the location of an executable program
  134.        dev        Same as devs but with argument
  135.        irq        Same as irqs but with argument
  136.  
  137. The 'find' script contains examples for using both the strcmp program and a
  138. recursive 'sh' function. As a disadvantage, it is relatively slow so that
  139. for everyday's use or on high-volume hard disks this script is better replaced
  140. by a program. There is also an example for an 'sh' function that makes the
  141. 'del' utility interactive and is intended to be added to a user's local
  142. profile file.
  143.  
  144.  
  145.  
  146. 4.     Command line options
  147. ---------------------------
  148.  
  149. The following command line arguments are available:
  150.  
  151. $ sh -?
  152. Syntax: sh [<opts>] [<scriptfile>] [<arg1>] ... [<argn>]
  153. Function: Operating system user interface (shell)
  154. Options:
  155.     -b            block input path while editing (default)
  156.     -C            redirected output requires '-' to overwrite file
  157.     -c            exit after reading and executing one command
  158.     -d[=<mode>]   enable debug output [for <mode>]
  159.     -e[=<path>]   print error explanations [using file <path>]
  160.     -f=<profile>  process profile file <profile>
  161.     -g            command completion includes execution directories
  162.     -h=<n>        set the # of history lines to <n>
  163.     -i            do not suppress shell messages (default if interactive)
  164.     -l            require 'logout' to logout (default automatic)
  165.     -p[=<prompt>] print prompt <prompt>
  166.     -r            do not process default profile files
  167.     -s            stop command execution
  168.     -t            echo input lines
  169.     -u            display references to unset variables
  170.     -v            verbose mode (same as '-t')
  171.     -w            kill all child processes and abort if carrier lost
  172.     -x            exit on error (default if non-interactive)
  173.     -y            try to make standard input path a tty
  174. All options may be prefixed by an 'n' character to invert their sense
  175.  
  176. Some of the options can also be set by environment variables or by built-in
  177. commands:
  178.  
  179.        Option                Environment variable          Built-in command
  180.        -e=<path>             setenv EMSG_FILE <path>
  181.        -h=<n>                setenv HISTORY <num>          history <n>
  182.        -p=<prompt>           setenv PS1 <prompt>
  183.  
  184. In addition, the 'set <option>' syntax can be used to set options within the
  185. current 'sh' session. If 'set -' is entered, all options except '-l' are set
  186. to their default values as described above. The environment variable HISTORY,
  187. by default, reflects the current size of the history buffer; setting it to
  188. another value does not influence the current history buffer size, but is taken
  189. as default value in any subsequently called interactive 'sh' session.
  190.  
  191.  
  192. 4.1.   Block input path while editing (-b)
  193. Normally, another program's output cannot be redirected to the standard and
  194. error output paths of an 'sh' session, while 'sh' is reading from its standard
  195. input path, e.g. during command line editing. The '-nb' option can be specified
  196. to change this behaviour; it causes 'sh' to use another read procedure so that
  197. the terminal is not blocked and another program can write to it. This option
  198. may be helpful to simultaneously use a terminal for both displaying messages
  199. on screen and running an 'sh' session. By default, the '-b' option is set. 
  200.  
  201.  
  202. 4.2.   Disallow files to be overwritten by redirected output (-C)
  203. By default, 'sh' will overwrite any existing file to which output is
  204. redirected using the '>', '2>', or '>>' syntax. If the '-C' option is set,
  205. however, 'sh' will write an error message and leave the file intact. This
  206. option is identical to 'bash' and also allows to simulate the redirection
  207. behavior of the Mware shell. A file can be forced to be overwritten, even
  208. if the '-C' option is set, by using the '>-', '2>-' or '>>-' syntax.
  209.  
  210.  
  211. 4.3.   Exit after reading and executing one command (-c)
  212. The '-c' option forces 'sh' to interpret the subsequent command line option
  213. as a command, to execute it as it were a script command and to stop execution
  214. thereafter immediately. Therefore, the command
  215.  
  216.        sh -c 'echo output string '
  217.  
  218. will display the string 'output string' on screen, while
  219.  
  220.        sh -c echo output string
  221.  
  222. executes 'echo' and, therefore, does not display anything on screen.
  223.  
  224.  
  225. 4.4.   Enable debug output (-d[=<mode>])
  226. If an interactive command or an 'sh' script does not execute correctly, the
  227. debug option may be used: The command 'set -d' enables debug messages in the
  228. current shell, and the command 'sh -d <proc>' shows debug messages during
  229. execution of the procedure <proc>. Debug messages of any child shell process
  230. (explicit and implicit ones) are enabled by setting the environment variable
  231. SHDEBUG to a non-zero value or to 'on' or 'ON' They are disabled when SHDEBUG
  232. is unset, set to 'off', 'OFF' or '0'.
  233.  
  234. In addition, the 'set -d=<mode>' syntax is available to separately enable and
  235. disable specific debug modes:
  236.  
  237.        <mode>  Debug category                                           Value
  238.        args    Command line arguments                                       1
  239.        evalg   Grave construct before being evaluated                       2
  240.        fork    Command being executed using chainc() of forkc()             4
  241.        grave   Evaluated grave construct before being executed              8
  242.        insert  String to be inserted, e.g. when replacing alias            16
  243.        match   String subjected to global expression match                 32
  244.        search  Attempts to locate a file for execution or a dir for chd    64
  245.        trace   Intermediate command to be executed                        128
  246.  
  247. These modes are stored internally as a bit pattern; the SHDEBUG environment
  248. variable is, by default, set to the above given value (or-ed together)
  249. whenever the debug mode changes. If, for example, 'match' and 'search' debug
  250. modes are requested during execution of the procedure <proc>, the command
  251.  
  252.        sh -d=search -d=fork <proc>
  253.  
  254. can be entered. The commands
  255.  
  256.        setenv SHDEBUG 68
  257.        <proc>
  258.  
  259. have, however, exactly the same effect, but only in the second example remains
  260. the debug mode enabled during all subsequent calls to 'sh' (unless SHDEBUG is
  261. reset to 0 or unset). Finally, the commands
  262.  
  263.        set -d=search -d=fork
  264.        <proc>
  265.  
  266. have, again, the same effect during execution of the procedure <proc> but, in
  267. addition, debugging is enabled in the current shell.
  268.  
  269.  
  270. 4.5.   Print error explanations (-e[=<path>])
  271. By default, the '-e' option is set to the environment variable EMSG_FILE or to
  272. '/dd/SYS/errmsg' if EMSG_FILE is not set, but it can be set to any other file
  273. that contains OS-9 error messages in the required format.
  274.  
  275.  
  276. 4.6.   Process profile file (-f=<profile>)
  277. The file specified as <profile> is processed before 'sh' starts command
  278. execution but after the default profile files '~/login', '/dd/SYS/profile' and
  279. '~/.profile' have been processed. This makes it possible to overwrite settings
  280. that have been made in one of the default profile files. 
  281.  
  282.  
  283. 4.7.   Command completion includes exec dirs (-g)
  284. Whenever 'sh' is in line editing mode, the cursor is at the first position of
  285. the input line or immediately follows a backquote, and the TAB key is hit,
  286. command completion is activated. By default, commands are searched in the
  287. alias list, in the list of currently available functions and in the list of
  288. built-in commands. The '-g' option is used to additionally include files in
  289. one of the execution directories (any of the PATH directories and execution
  290. directory). 
  291.  
  292.  
  293. 4.8.   Set the # of history lines (-h=<n>)        
  294. The default number of history lines is the number specified in the HISTORY
  295. environment variable or 0, if undefined. The '-h=<n>' option can be used to
  296. define any number of history lines between 1 and 500.
  297.  
  298.  
  299. 4.9.   Do not suppress shell messages (-i)
  300. When a program returns another value than 0 or 1 during an interactive 'sh'
  301. session, this error number and, optionally, the error code are displayed on
  302. screen, since the '-i' option is automatically set, if 'sh' runs interactively.
  303. The '-ni' option that is set by default only during execution of an 'sh'
  304. script can be used to explicitly suppress shell messages. On the other hand,
  305. the '-i' option can be set to explicitly force error messages even during
  306. script execution.  
  307.  
  308.  
  309. 4.10.  Require "logout" to logout (-l)
  310. The '-l' option is automatically set, if at least one keycap entry starts with
  311. the escape character; otherwise, it is unset so that an 'sh' session can be
  312. stopped just by entering the eof character (normally Esc).
  313.  
  314.  
  315. 4.11.  Define prompt (-p[=<prompt>])
  316. By default, the '-p' option is set to the environment variable PS1 or, if not
  317. set, to '@# ' for a super-user and to '@% ' for any other user, respectively.
  318. The program entry in the above given password file
  319.  
  320.        sh -ep="<$HOST/$USER/sh@>$CWD:"
  321.  
  322. will invoke 'sh', for example, with the prompt
  323.  
  324.        <thle27/carsten/sh1>/h0/SH/DOC:
  325.  
  326. and define the standard error message file '/dd/SYS/errmsg' for the generation
  327. of error texts.
  328.  
  329.  
  330. 4.12.  Do not process default profile files (-r)
  331. Normally, the files '~/login', '/dd/SYS/profile' and '~/.profile', and the files
  332. '/dd/SYS/sh.logout' and '~/.logout' are executed  before 'sh' begins command
  333. execution and before it exits, respectively. If the '-r' option is specified,
  334. however, none of the named files are processed.
  335.  
  336.  
  337. 4.13.  Stop command execution (-s)
  338. This option causes 'sh' to immediately stop command execution; it is only
  339. available during script execution and can, for example, be used for testing and
  340. debugging purposes. Any command after
  341.  
  342.        set -s
  343.  
  344. is prevented from being executed. It must, however, be noticed that this
  345. command is irreversible, since once command execution has beed stopped, no
  346. other command can be executed - even not a
  347.  
  348.        set -ns
  349.  
  350. command.
  351.  
  352.  
  353. 4.14.  Echo input lines (-t)
  354. Every input line is echoed to the output path of the current 'sh' session.
  355.  
  356.  
  357. 4.15.  Display references to unset variables (-u)
  358. Normally, a reference to an undefined variable does not result in an error
  359. message but the variable is defined and an empty string is assigned to it. In
  360. consequence, it is not possible to differentiate between an undefined variable
  361. and a variable that intentionally has been set to contain an empty string,
  362. e.g. using the assign command
  363.  
  364.        var=""
  365.  
  366. If, however, the '-u' option is specified, such differentiation is possible,
  367. since this options causes 'sh' to produce an error message whenever an
  368. undefined variable is referenced.
  369.  
  370.  
  371. 4.16.  Verbose mode (-v)            
  372. Every input line is echoed to the output path of the current 'sh' session
  373. (same as '-t' option).
  374.  
  375.  
  376. 4.17.  Kill all child processes and abort if carrier lost (-w)
  377. To become effective, this option requires that 'sh' is the primary (login)
  378. shell and that the driver of the standard input port supports the installation
  379. of a data-carrier-detect interrupt. If this is the case and the carrier
  380. gets lost, 'sh' sends a HANGUP signal to all child processes and aborts with
  381. error E_HANGUP (220).
  382.  
  383.  
  384. 4.18.  Exit on error (-x)
  385. When this option is set and an error occurs, the current 'sh' session exits
  386. immediately. This is the default behaviour during execution of a shell script,
  387. while an interactive 'sh', by default, does not exit on error.
  388.  
  389.  
  390. 4.19.  Try to make standard input path a tty (-y)
  391. The 'sh' built-in command 'read' requires that standard input path is a
  392. terminal. If an 'sh' script containing the 'read' command is started by
  393. another program that does not provide correct setting of the standard input
  394. path but standard output or standard error output path is a terminal, the '-y'
  395. option can be specified in which case 'sh' checks standard output and standard
  396. error path and uses one of them for input, if possible.
  397.  
  398.  
  399.  
  400. 5.     The termcap data base and command line editing and history
  401. -----------------------------------------------------------------
  402.  
  403. 5.1.   The termcap data base
  404. The termcap data base is used for two different purposes; first, to store
  405. specific commands that can be sent to the terminal, e.g. for cursor movement,
  406. and, second, for the interpretation of special key sequences that are sent
  407. by the terminal, e.g. from the arrow keys. The latter are needed for command
  408. line editing and will be covered in the next paragraph. 'sh' for OS-9 supports
  409. the following terminal commands that are searched in the termcap data base
  410. when the program starts and whenever the environment variable TERM is modified:
  411.  
  412.        Action                                  Default        Termcap name
  413.        Pad string ............................. None               pc
  414.        Clear to end of line ................... None               ce
  415.        Backspace cursor ....................... Ctrl-H             bc
  416.        Enter standout mode .................... None               so
  417.        End standout ........................... None               se
  418.        Bell ................................... Ctrl-G             bl
  419.        Clear screen ........................... None               cl
  420.        Special keys on HP terminals ........... None               hs
  421.        Enable above special keys .............. None               hx
  422.        Normal cursor style for insert mode .... None               cQ 
  423.        Cursor style for overstrike mode ....... None               cI
  424.        Start keypad transmit mode ............. None               ks
  425.        End keypad transmit mode ............... None               ke
  426.  
  427. The strings to start and to stop keypad transmit mode are sent, if set, after
  428. 'sh' enters interactive mode and before 'sh' is finishing, respectively. The
  429. 'ks' string is also sent whenever the TERM environment variable is modified.
  430.  
  431.  
  432. 5.2.   Command line editing and history
  433. One of the most important features of 'sh' for OS-9 is the command line
  434. editing and history function. Please note that editing of the current command
  435. line is always active; the history function is only active, if enabled using
  436. the '-h=<lines>' option when 'sh' is started or using the 'history <lines>'
  437. syntax at a later time.
  438.  
  439. The following commands are available; default keys are used, if the particular
  440. termcap entry is not specified.  
  441.  
  442.        Command                                    Default key    Termcap name
  443.        Delete previous character ................ 'bse' option       -
  444.        Delete character under cursor............. Del (0x7f)         kD
  445.        Cursor backward .......................... Ctrl-b             kl
  446.        Cursor forward ........................... Ctrl-f             kr
  447.        Next history line ........................ Ctrl-n             kd
  448.        Previous history line .................... Ctrl-p             ku
  449.        Cursor to start of line .................. Ctrl-a             kh
  450.        Alternate cursor to start of line ........ Ctrl-a             ka
  451.        Cursor to end of line .................... Ctrl-z             kH
  452.        Alternate cursor to end of line .......... Ctrl-e             kA
  453.        Clear to end of line ..................... Ctrl-k             kE
  454.        Reset terminal ........................... Ctrl-g             kS
  455.        Delete current line ...................... 'del' option       kL
  456.        Transpose current and previous character . Ctrl-t             kT
  457.        Toggle insert/overwrite mode ............. Ctrl-v             kI
  458.        Complete name ............................ Ctrl-i (TAB)       ta
  459.        Clear screen ............................. Ctrl-l             kc
  460.        Insert from paste buffer ................. Ctrl-y             ki
  461.        Abandon edit line ........................ Ctrl-c             kq
  462.        Reverse-incremental history search ....... Ctrl-r             kQ
  463.        Word delete .............................. Esc,d              kX
  464.        Uppercase word ........................... Esc,u              kU
  465.        Lowercase word ........................... Esc,l              kY
  466.        Capitalize word .......................... Esc,c              kC
  467.        Word forward (next word).................. Esc,f              kF
  468.        Word backward (previous word) ............ Esc,b              kB
  469.        New line ................................. 'eor' option       -
  470.        Logout ................................... 'eof' option       -
  471.  
  472.  
  473. 5.3.   Detailed description of all line editing commands
  474.  
  475. Delete previous character ('bse' from terminal path options)
  476. The character to the left of the cursor, if any, is removed from the current
  477. edit line and the cursor is moved one position to the left. This function is
  478. normally assigned to the 'Backspace' key.
  479.  
  480. Delete character under cursor (Del/termcap kD)
  481. The character under the cursor is deleted form the current edit line but the
  482. cursor position remains unchanged. This function is normally assigned to the
  483. 'Delete' key.
  484.  
  485. Cursor backward (Ctrl-b/termcap kl)
  486. The cursor is moved one character to the left, if not already at the leftmost
  487. position. This function is normally assigned to the 'Arrow left' key.
  488.  
  489. Cursor forward (Ctrl-f/termcap kr)
  490. The cursor is moved one character to the right, if not already at the rightmost
  491. position. This function is normally assigned to the 'Arrow right' key.
  492.  
  493. Next history line (Ctrl-n/termcap kd)
  494. The current edit line is replaced by the next line in history buffer, if the
  495. history stack pointer does not already point to the last entry, and the
  496. cursor is moved to the end of the line. This function is normally assigned to
  497. the 'Arrow down' key.
  498.  
  499. Previous history line (Ctrl-p/termcap ku)
  500. The current edit line is replaced by the previous line in history buffer, if the
  501. history stack pointer does not already point to the first entry, and the
  502. cursor is moved to the end of the line. This function is normally assigned to
  503. the 'Arrow up' key.
  504.  
  505. Cursor to start of line (Ctrl-a/termcap kh)
  506. The cursor is moved to the first position of the edit line, if not already
  507. there. The content of the current edit line remains unchanged.
  508.  
  509. Alternate cursor to start of line (Ctrl-a/termcap ka)
  510. Same as above, intended to allow the use of both cursor key (Home) and, for
  511. example, uEmacs control key.
  512.  
  513. Cursor to end of line (Ctrl-z/termcap kH)
  514. The cursor is moved past the last position of the edit line, if not already
  515. there. The content of the current edit line remains unchanged.
  516.  
  517. Alternate cursor to end of line (Ctrl-e/termcap kA)
  518. Same as above, intended to allow the use of both cursor key (End) and, for
  519. example, uEmacs control key.
  520.  
  521. Clear to end of line (Ctrl-k/termcap kE)
  522. The string from the current cursor position to end of line is deleted and
  523. saved in the paste buffer but not in the history stack. The cursor is not
  524. moved.
  525.  
  526. Reset terminal (Ctrl-g/termcap kS)
  527. The terminal settings are restored to the condition that was found when 'sh'
  528. was started. This function is intended to cope with a situation when 'sh' has
  529. forked a program that did not restore the terminal settings appropriately.
  530.  
  531. Delete current line ('del' from terminal path options, kL)
  532. The entire edit string is deleted and saved in the paste buffer but not in
  533. the history stack. The cursor is moved to the leftmost position.
  534.  
  535. Transpose current and previous character (Ctrl-t/termcap kT)
  536. The two characters, under the cursor and to the left of the cursor, are
  537. exchanged.
  538.  
  539. Toggle insert/overwrite mode (Ctrl-v/termcap kI)
  540. By default, any character entered from the keyboard is inserted into the
  541. edit line. This command, if used once, changes to overwrite mode, i.e. a
  542. newly entered character replaces the character under the cursor. If used a
  543. second time, the default behavior is restored.
  544.  
  545. Complete name (Ctrl-i/termcap ta)
  546. The TAB key (or the key specified by the 'ta' termcap entry) causes 'sh' to
  547. match the already entered string as a command, as a file name, as a shell
  548. variable name or as a user name, if it is the first word in a line, it is a
  549. valid file name, its first character is '$' or its first character is '~',
  550. respectively. In case there is more than one match, the terminal beeps and the
  551. user may hit the same key again in which case the entire list of matching
  552. names is displayed. Should more than 100 names match, the user can suppress
  553. the display. If the completed string specifies a file name or a command, a
  554. space is appended. A slash is appended, if it specifies a valid directory.
  555. The name to be completed may contain wild card characters and regular
  556. expressions. If it is not a shell variable, it may also contain shell
  557. variables and the tilde symbol that are both evaluated before completion
  558. takes place. By default, commands are searched in the alias list, in the list
  559. of currently available functions and in the list of built-in commands. The
  560. files in one of the execution directories (any of the PATH directories and
  561. execution directory) may be included into command name completion by a shell
  562. option (-g). Finally, if the first character of an input line is the
  563. exclamation mark ('!') followed by a match string and the completion key is
  564. entered, the most recent history line that matches the string is inserted.
  565. History line completion never reports more than one match, even if there are
  566. less recent entries that also match. As with the normal history syntax, it
  567. is also possible to enter an exclamation mark followed by a number in which
  568. case the history line at this number is inserted. In contrast to the other
  569. completion modes, history line completion is not limited to words - the entire
  570. history line including any white space is inserted. 
  571.  
  572. Clear screen (Ctrl-l/termcap kc)
  573. The screen is cleared, the cursor is moved to the upper left position, and the
  574. current prompt and the current edit line, if any, are written to the first
  575. screen line.
  576.  
  577. Insert from paste buffer (Ctrl-y/termcap ki)
  578. Any string that has been saved to paste buffer using the "clear to end of
  579. line", "delete current line" or "abandon edit line" command is pasted into the
  580. current edit line.
  581.  
  582. Abandon edit line (Ctrl-c/termcap kq)
  583. The current edit line is copied into paste buffer but not saved in history
  584. stack, the string "* Abandon *", a carriage return and a new prompt are
  585. written to screen, and the current edit line is cleared.
  586.  
  587. Reverse-incremental history search (Ctrl-r/termcap kQ)
  588. Every subsequently entered character is appended to a search string that is
  589. looked up in the history lines starting from the most recent entry. Whenever
  590. this line editing command is entered another time, the next less recent
  591. occurrence of the search string in the history lines is displayed on screen.
  592. If a match cannot be found, the terminal beeps and the display does not change.
  593. The reverse-incremental history search can be left using three different ways:
  594. i) If the enter key is hit, the currently selected history line is copied
  595. into the edit command line and the command is executed. ii) If the left-arrow,
  596. right-arrow, begin-of-line, end-of-line or backspace key is hit, the currently
  597. selected history line is copied into the command line, the respective move or
  598. backspace command is applied and edit mode is resumed. iii) If any other
  599. non-alphanumeric key is hit, the search is canceled, the previous edit line is
  600. restored and edit mode is resumed.
  601.  
  602. Word delete (Esc,d/termcap kX)
  603. The word under the cursor beginning at the current cursor position is copied
  604. into paste buffer and deleted from the current edit line.
  605.  
  606. Uppercase word (Esc,u/termcap kU)
  607. The characters of the word under the cursor beginning at the current cursor
  608. position are changed to uppercase.
  609.  
  610. Lowercase word (Esc,l/termcap kY)
  611. The characters of the word under the cursor beginning at the current cursor
  612. position are changed to lowercase.
  613.  
  614. Capitalize word (Esc,c/termcap kC)
  615. The characters of the word under the cursor beginning at the current cursor
  616. position are changed to lowercase, the first character is made uppercase.
  617.  
  618. Word forward (Esc,f/termcap kF)
  619. The cursor is moved to the first character of the word that follows the word
  620. under the cursor.
  621.  
  622. Word backward (Esc,b/termcap kB)
  623. The cursor is moved to the first character of the word that precedes the word
  624. under the cursor.
  625.  
  626. New line ('eor' from terminal path options)
  627. The edit function is left, the current edit line is sent to the 'sh' input
  628. line parser and the commands, if any, are executed.
  629.  
  630. Logout ('eof' from terminal path options)
  631. If the '-l' option is not enabled, this character causes 'sh' to execute
  632. '$HOME/.logout' and '/dd/SYS/sh.logout', to stop execution and to return to
  633. the previous program. If history is enabled, the contents of the history
  634. buffer are written to the file '$(HOME)/.sh_history'. 
  635.  
  636.  
  637.  
  638. 6.     General concept of the shell syntax and symbols
  639. ------------------------------------------------------
  640.  
  641. The general concept of the shell syntax is based on simple commands that are
  642. parsed, possibly substituted and, if appropriate, passed to the operating
  643. system. A simple command is a sequence of optional variable assignments
  644. followed by whitespace-separated words and redirections, and terminated by a
  645. control operator. The first word specifies the command to be executed. The
  646. remaining words are passed as arguments to the invoked command. The return
  647. value of a simple command is its exit status. Several simple commands may be
  648. concatenated into a pipe using one of the equivalent pipe symbols 
  649. ('|' or '!'), and several pipes may be concatenated into a list using one 
  650. of the different list symbols (;, &, &&, ||) and terminated by one of the
  651. terminator symbols (;, &, <newline>). Except in the case where a symbol
  652. character is not a legal component of a word such as the '&' symbol, symbols
  653. must be separated with whitespace from words and from each other. This is a
  654. fundamental difference to the concept of many computer languages, in
  655. particular to the C language. A comparable fundamental difference applies to
  656. string elements that must always be marked as such in the C language (using
  657. double-quotes) but do not need to be marked in the the shell language, since
  658. there are only strings anyway. The unspecific use of double-quotes may even
  659. lead to unwanted effects, since they specifically protect a string against
  660. expansion.
  661.  
  662.  
  663. 6.1.   Pipe symbol ('|' or '!')
  664. Any two commands separated by the pipe symbol are started concurrently the 
  665. standard output path of the first program being redirected to the standard
  666. input path of the second program via an unnamed pipe.
  667.  
  668.  
  669. 6.2.   Redirection symbols ('<', '>', '2>', '>>', '>+', '>-', '>&', '>&-')
  670.        Condensed redirection ('<>', '<>>', '<>>>', '>>>' etc.)  
  671. Standard input, standard output and standard error output are redirected
  672. using the '<', '>' and '2>' redirection symbols, respectively. Any existing
  673. file is silently overwritten. The output is appended, if the '>>' symbol 
  674. ('Bourne mode' only) or the '>+' is used. If in 'Mware mode', the '>>' symbol
  675. redirects standard error path. By default, 'sh' is in 'Bourne mode'; it
  676. is switched to 'Mware mode', if '*' is used as comment symbol in a script. The
  677. '#' comment symbol switches back to 'Bourne mode'. The '>-' symbol is only
  678. implemented for the sake of compatibility with the Mware shell; it is,
  679. however, not different from the '>' symbol. In addition, the outputs from
  680. several paths may be merged together using the '<from>>&<to>' syntax, where
  681. <from> specifies the output path that is going to be closed and be merged into
  682. path <to>. This syntax is, for example, helpful to grep through a program's
  683. error output. The following command will only display those GNU C compiler
  684. options that are related to the '-M' option:
  685.  
  686.        gcc2 -? 2>&1 | grep ' -M'
  687.  
  688. The order in which redirections are specified is significant. The shell
  689. evaluates redirections left-to-right. For example: 
  690.  
  691.        <cmd> 1><file> 2>&1 
  692.       
  693. first associates file descriptor 1 with file <file>. It associates file
  694. descriptor 2 with the file associated with file descriptor 1 (that is, <file>).
  695. If the order of redirections were reversed, file descriptor 2 would be
  696. associated with the terminal (assuming file descriptor 1 had been) and file
  697. descriptor 1 would be associated with file <file>.
  698.  
  699. If a '-' sign is specified after the merge symbol (&) instead of a path
  700. number, this path is simply closed, e.g. '2>&-' will suppress any output on
  701. standard error path. Finally, the condensed redirection syntax ('<>', '<>>',
  702. '<>>>', '>>>' etc.) is understood, which may be followed by a '+' a '-' symbol
  703. as explained above. 
  704.  
  705. 6.3.   History symbol ('!', if first character of an input line)
  706. There are several ways to directly execute commands from the history buffer.
  707. The history symbol alone will execute the most recent command; if followed by
  708. a number, the history line with this number is executed. If the history symbol
  709. is followed by a match string, the most recent command that matches this
  710. string is executed. If the completion key is entered at the end of a line
  711. that starts with the history symbol, history completion is attempted, i.e.
  712. the most recent history line that matches or the history line with the
  713. specified line number, if it exists, is inserted into the current edit line.  
  714.  
  715.  
  716. 6.4.   Assignment symbol ('=')
  717. A new shell variable is created and a value assigned. The variable 'var' is,
  718. for example, set and defined, if the command
  719.  
  720.        var="sh = flexibility"
  721.  
  722. is entered. The variable can be recalled when preceded by the '$' sign (see
  723. below). By default, the newly created variable is not exported when a child
  724. process is forked. Another assignment may follow immediately on the same line,
  725. e.g.
  726.  
  727.        abc=123 def=456
  728.  
  729. In addition, a single assignment or several assignments may be followed by
  730. any legal shell command construct, again on the same line. In this special
  731. case, the variables will be made exportable by default and will be removed
  732. after execution of the command. Any existing environment variable may be
  733. shadowed as demonstrated in the example:
  734.  
  735.        # setenv TERM vt100
  736.        # echo $TERM
  737.        vt100
  738.        # TERM=vt320 printenv TERM
  739.        vt320
  740.        # echo $TERM
  741.        vt100
  742.  
  743.  
  744. 6.5.   Variable symbol ('$')
  745. Any environment variable and shell variable can be recalled when the
  746. variable's name preceded by the '$' sign is entered. The sequence '$<n>'
  747. recalls the arguments of a shell script or variables that have been set using
  748. the 'set' command. The following shell built-in variables are additionally
  749. available:
  750.  
  751.      Symbol        Returns
  752.        $#          the number of arguments (updated)
  753.        $*          concatenated command line arguments (updated)
  754.        "$*"        command line arguments concatenated with first
  755.                    IFS character (updated)
  756.        $@          concatenated command line arguments, same as $* (updated)
  757.        "$@"        command line arguments expanded into separate words
  758.                    (updated)
  759.        $-          shell options (updated)
  760.        $?          value returned by the last command or function executed
  761.        $$          the shell's process ID
  762.        $<n>        the <n>th command line argument, see above (updated)
  763.        ${~0}       same as $$
  764.        ${~}        the shell's parent proces ID
  765.        ${~1}       same as ${~}
  766.        ${~2}       the shell's grandparent process ID
  767.        ${~<n>}     the shell's parent process ID degree <n>
  768.        $!          the process ID of the most recently invoked concurrent
  769.                    command
  770.        $:          the shell's current priority (updated)
  771.        $.          the shell's current user group number (updated)
  772.        $,          the shell's current user ID (updated)
  773.        $var        value of var, empty if var is not defined.
  774.        ${var}      same as above, required if var is followed by a
  775.                    character that could be part of a variable's name.
  776.        ${var=new}  value of var if defined, 'new' otherwise.
  777.                    If undefined, $var is set to 'new'.
  778.        ${var:=new} value of var if defined and not empty, 'new' otherwise.
  779.                    If undefined, $var is set to 'new'.
  780.        ${var-new}  value of var if defined, 'new' otherwise.
  781.                    If undefined, $var remains unchanged.
  782.        ${var:-new} value of var if defined and not empty, 'new' otherwise.
  783.                    If undefined and not zero, $var remains unchanged.
  784.        ${var+new}  'new' if var is defined, empty otherwise.
  785.        ${var:+new} 'new' if var is defined and not empty, empty otherwise.
  786.        ${var?}     value of var if defined, 'var: parameter not set' is
  787.                    printed otherwise and 'sh' aborts, if interactive.
  788.        ${var:?}    value of var if defined and not empty, 'var: parameter null
  789.                    or not set' is printed otherwise and 'sh' aborts, if
  790.                    interactive.
  791.        ${var?str}  value of var if defined, 'var: str' is printed otherwise
  792.                    and 'sh' aborts, if interactive.
  793.        ${var:?str} value of var if defined and not empty, 'var: str' is
  794.                    printed otherwise and 'sh' aborts, if interactive.
  795.  
  796. There is one specific exception from the rule for shell variable evaluation:
  797. The sequence '$temp$' is always returned unprocessed so that OS-9 V3.0 names
  798. for temporary files ('_$temp$_<xxxx>') can be entered as if there were no '$'
  799. characters (required for execution of 'cfp' generated files).
  800.  
  801.  
  802. 6.6.   Concurrent execution symbol ('&')
  803. A command delimited by the '&' symbol is executed in the background and its
  804. process ID is written to screen. The 'wait' command can be used to abolish
  805. concurrent execution and to wait until the command is finished.
  806.  
  807.  
  808. 6.7.   Sequential execution symbol (';')
  809. Several commands that are separated by the ';' symbol will be executed
  810. sequentially, same as if the commands had been entered separately.
  811.  
  812.  
  813. 6.8.   Evaluation symbol ('`')
  814. Any command or list of commands embedded in backquotes will first be
  815. executed and its output be treated as shell input string. If, for example,
  816. only memory resident RBF disk descriptor modules d0 to d3 and h0 to h3 are
  817. to be saved, the commands
  818.  
  819.        for i in `mdir -ut=desc "??" | grep [dh][0-3]`
  820.        do
  821.          save $i
  822.        done
  823.       
  824. will do the job.
  825.  
  826.  
  827. 6.9.   Comment ('#' and '*') and execution ('@', '~*' and '*!') symbols
  828. Any line that starts with one of the comment symbols is ignored. There is,
  829. however, one exception from this rule: The first line of a procedure file may
  830. indicate the shell (or any other) program for processing using the '#!<prog>'
  831. syntax. If a fully qualified file name is specified that cannot be found
  832. (e.g. '#!/bin/sh'), its base name ('sh' in the example) is tried. There are
  833. important differences between the two comment symbols: The '#' symbol can
  834. appear at the beginning of a word anywhere in a command line and switches the
  835. I/O syntax parser to 'Bourne mode' so that the '>>' redirection syntax is
  836. recognized as append symbol. The '*' symbol can only appear in procedure files
  837. and only at the beginning of a command (i.e. at the beginning of a line or
  838. following a semicolon) and switches the I/O parser to 'Mware mode' so that the
  839. '>>' syntax is recognized as redirection of standard error path.
  840.  
  841. In addition, the execution symbol '@' (only if first character of a procedure
  842. file) informs 'sh' that the 'zsh' shell is required, and the character sequence
  843. '~*' (only if first two characters of a procedure file) indicates that this
  844. procedure file requires Mware's command file processor 'cfp' for execution.
  845. Last not least, the character sequence '*!' causes 'sh' to fork the Mware
  846. shell 'mshell' to execute the script file.
  847.  
  848.  
  849.  
  850. 6.10.  Test symbol ('[')
  851. This symbol is merely a synonym for the 'test' command. In contrast to 'test',
  852. however, end of the test condition may be marked using the ']' character. 
  853.  
  854.  
  855. 6.11.  Shell level symbol (@)
  856. This symbol is replaced by the current shell level (stored in the environment
  857. variable _sh).
  858.  
  859.  
  860. 6.12.  Single quote (')
  861. Used to prevent a character, e.g. space, wild card symbol etc., from being
  862. treated by the command line parser. Only the single quote, not the double
  863. quote, also prevents shell variables and backslashes from being evaluated. The
  864. following command allows, for example, to redefine the prompt string:
  865.  
  866.        setenv PS1 '$CWD:'
  867.  
  868.  
  869. 6.13.  Double quote (")
  870. Used to prevent a character, e.g. space, wild card symbol etc., from being
  871. treated by the command line parser. In contrast to single quotes, shell
  872. variables within double quotes are evaluated. The following command will
  873. display all descriptors in memory that have 't' as first character:
  874.  
  875.        mdir -et=desc "t*"
  876.  
  877.  
  878. 6.14.  Mark symbol (<<)
  879. Used to mark an end-of-file string for so-called here documents. Subsequently
  880. entered lines are written to an intermediate file until the mark string is
  881. reached, e.g.:
  882.  
  883.        cat << ENDMARK >textfile
  884.        You are reading
  885.        the file 'textfile'.
  886.        ENDMARK
  887.  
  888.        list textfile
  889.        You are reading
  890.        the file 'textfile'.
  891.  
  892. The intermediate file is created on the directory that is specified in the
  893. TMPDIR environment variable or '/dd/TMP', if undefined. It is silently created,
  894. if not yet available. The file name of the temporary file is 'sh' suffixed by
  895. the 6-digit number of the shell's process ID. Any '$', '\' or grave (`...`)
  896. construct in the here document are substituted unless the mark string is
  897. quoted or preceded by a backslash. For example, in the following
  898.  
  899.        cat << ENDMARK >pidprio
  900.        This shell's pid is $$ and its priority is $:
  901.        ENDMARK
  902.        list pidprio
  903.        This shell's pid is 000012 and its priority is 128
  904.  
  905. substitution takes place whereas in
  906.  
  907.        cat << 'ENDMARK' >getpid
  908.        The shell's pid can be obtained using the $$ symbol
  909.        ENDMARK
  910.        list getpid
  911.        The shell's pid can be obtained using the $$ symbol
  912.  
  913. the '$$' symbol or in
  914.  
  915.        cat << \ENDMARK >getprio
  916.        The shell's priority can be obtained using the $: symbol
  917.        ENDMARK
  918.        list getprio
  919.        The shell's priority can be obtained using the $: symbol
  920.  
  921. the '$:' symbol is taken literally.
  922.  
  923.  
  924. 6.15.  Escape character symbol (\)
  925. Used to enter characters that have a special meaning in the 'sh' context and
  926. also non-printable ASCII characters. The following command, for example,
  927. displays all lines of a text file that contain the dollar character at end of
  928. line:
  929.  
  930.        grep \\\$\$ file.c
  931.  
  932. Note that the four escape characters have different meanings; the first two
  933. encode the escape character itself to be passed to the grep program, the two
  934. others are necessary to enter the dollar character without being treated as
  935. the 'sh' variable denominator. The two dollar characters also have different
  936. meanings; the first one specifies anchored search (only at end of line) and
  937. the second specifies the dollar character to search. When received by the grep
  938. program, the command line arguments will be transformed to
  939.  
  940.        grep \$$ file.c
  941.  
  942. Another example relates to the conversion of UNIX text files to OS-9. The
  943. following command does appropriate translation of the line-feed (0x0a) line
  944. delimiter to carriage-return (0x0d)
  945.  
  946.        tr \\l \\n <unix >os9
  947.  
  948. and is functionally equivalent to
  949.  
  950.        tr \\0a \\0d <unix >os9
  951.  
  952. but could also be written as
  953.  
  954.        tr '\l' '\n' <unix >os9
  955.  
  956. or as
  957.  
  958.        tr '\0a' '\0d' <unix >os9
  959.  
  960.  
  961. The built-in echo command recognizes the following special escape characters:
  962.  
  963.      Symbol  Output   ASCII   Function
  964.        \a     0x07     BEL    Alert
  965.        \b     0x08     BS     Backspace
  966.        \c                     Suppress carriage return (same as -r option)
  967.        \f     0x0c     FF     Form feed
  968.        \l     0x0a     NL     New line
  969.        \n     0x0d     CR     Carriage return
  970.        \r     0x0d     CR     Carriage return
  971.        \t     0x09     TAB    Forward tab
  972.        \v     0x0b     VT     Vertical tab
  973.        \\     '\'             Backslash    
  974.        \OOO                   Any character, if OOO is an octal character that
  975.                                 has a value of less than 256 (octal 377)
  976.        \XX                    Any character, if XX is a hexadecimal character
  977.                                 (upper or lower case)
  978.  
  979.  
  980. 6.16.  Home symbol (~)
  981. The tilde is replaced by the current HOME directory or, if followed by a valid
  982. user name, by this user's home directory. In addition, the tilde and the
  983. following character are replaced by the current working directory, if the tilde
  984. is followed by a '+' sign and by the last working directory, if followed by a
  985. '-' sign, repectively. These mechanisms are also available when the tilde is
  986. the first character of a file name that is subjected to TAB file name
  987. completion.
  988.  
  989.  
  990.  
  991. 7.     Environment variables
  992. ----------------------------
  993.  
  994. 7.1.   _sh
  995. This variable contains the shell level, i.e. it can be used to display how
  996. often a child shell has been forked. It cannot be unset.
  997.  
  998.  
  999. 7.2.   EMSG_FILE
  1000. The file that may optionally be specified in the EMSG_FILE environment
  1001. variable is used for printing error texts, same as '-e[=<path>]' command line
  1002. option. In contrast to the command line option, the environment variable
  1003. EMSG_FILE must be set before 'sh' is started to become effective. Setting
  1004. it to another value within an 'sh' session does not influence the current
  1005. error message file. Whenever another error message file is specified using
  1006. the 'set -e=<path>' command, the environment variable EMSG_FILE is updated
  1007. implicitly. It cannot be unset.
  1008.  
  1009.  
  1010. 7.3.   HISTORY
  1011. The value that may optionally be specified in the HISTORY environment variable
  1012. defines the size of the history buffer, if set before 'sh' is started. Setting
  1013. it to another value within an 'sh' session does not influence the current
  1014. history buffer size. Whenever the current history buffer is resized, e.g.
  1015. using the 'history <num>' command, HISTORY is updated implicitly.
  1016.  
  1017.  
  1018. 7.4.   TMPDIR
  1019. The TMPDIR environment variable is used to store temporary data such as here
  1020. documents, default is '/dd/TMP'. If the specified or the default directory
  1021. is not available, it is automatically created when needed for the first time.
  1022. The environment variable TMPDIR cannot be unset.
  1023.  
  1024.  
  1025. 7.5.   PATH 
  1026. The colon-separated directories in the PATH environment variable are scanned
  1027. whenever the first string of an input line is not a built-in command, is not a
  1028. fully qualified file name and does not specify an executable module that is
  1029. resident in memory.
  1030.  
  1031. When a file is found in one of the PATH directories, an attempt is made to
  1032. execute the file; default is '/dd/CMDS', if the PATH variable is empty. The
  1033. first file found is executed, irrespective of whether it is a binary program
  1034. or a procedure file. In the latter case, the file is, of course, not directly
  1035. executed but forked using the shell that is taken from the file (see above)
  1036. or, otherwise, that is specified in the SHELL environment variable. If the file
  1037. is not found in one of the PATH directories, an attempt is made to execute it
  1038. from the current execution directory, but this requires that the file has the
  1039. execute attribute set. As above, also a file in the current execution directory
  1040. may be either a binary program or a procedure file. The dot ('.') symbol in the
  1041. PATH list (e.g. '.:/dd/CMDS') has a special meaning: It always refers to the
  1042. current data directory and not to the current execution directory, since the
  1043. latter is scanned anyway. The same rule applies to the './' prefix (e.g.
  1044. './procedure') that also refers to the current data directory. The environment
  1045. variable PATH cannot be unset.
  1046.  
  1047.  
  1048. 7.6.   HOME
  1049. The HOME environment variable is expected to contain the home directory. This
  1050. is the directory where the '.profile' file is searched and where the history
  1051. file '.sh_history' is saved, if history is enabled. The HOME environment
  1052. variable defaults to '/dd'. It cannot be unset.
  1053.  
  1054.  
  1055. 7.7.   CDD
  1056. The CDD environment variable contains the disk device of the current data
  1057. directory and is automatically updated when a 'chd' command is executed. It
  1058. is read-only and cannot be unset.
  1059.  
  1060.  
  1061. 7.8.   CDL
  1062. The CDL environment variable contains the lowest level of the current data
  1063. directory (not the entire tree) and is automatically updated when a 'chd'
  1064. command is executed. Intended to cope with long $CWD strings that are part of
  1065. the prompt. The PS1 environment variable can, for example, be set to the
  1066. expression
  1067.  
  1068.        <$HOST/$USER/sh@>$CDD/-/$CDL:
  1069.  
  1070. instead of
  1071.  
  1072.        <$HOST/$USER/sh@>$CWD:
  1073.  
  1074. so that the prompt remains reasonably short even when the current directory
  1075. points to a deep level in the directory tree. The CDL environment variable is
  1076. read-only and cannot be unset.
  1077.  
  1078.  
  1079. 7.9.   CDPATH
  1080. The CDPATH environment variable may contain a colon separated list of
  1081. directories. These directories are searched when the argument to the
  1082. 'cd <newdir>' or 'chd <newdir>' built-in command is not found in the current
  1083. directory.
  1084.  
  1085.  
  1086. 7.10.   CWD
  1087. The CWD environment variable contains the current data directory and is
  1088. automatically updated when a 'cd' or a 'chd' command is executed. If the CWD
  1089. environment is already set when 'sh' for OS-9 is started, a 'chd $CWD' command
  1090. is executed implicitly; it is set to the current directory, otherwise. The
  1091. CWD environment variable is read-only and cannot be unset.
  1092.  
  1093.  
  1094. 7.11.  LWD
  1095. The LWD environment variable contains the previous current data directory and
  1096. is automatically updated when a 'cd' or a 'chd' command is executed.
  1097.  
  1098.  
  1099. 7.12.  TERM
  1100. The TERM environment variable is used to select the appropriate termcap
  1101. setting. This is the only environment variable that, by default, also acts on
  1102. the current 'sh' session. It cannot be unset.
  1103.  
  1104.  
  1105. 7.13.  IFS
  1106. The IFS environment variable contains a list of characters that separate words
  1107. in arguments. It cannot be unset.
  1108.  
  1109.  
  1110. 7.14.  OLDPWD
  1111. The OLDPWD environment variable contains the previous current data directory
  1112. and is automatically updated when a 'cd' or a 'chd' command is executed. Its
  1113. behavior is identical to the LWD environment variable.
  1114.  
  1115.  
  1116. 7.15.  PPID
  1117. The PPID environment variable contains the process ID of the parent process of
  1118. the current 'sh'. It is identical to ${~} and ${~1}, is read-only and cannot
  1119. be unset.
  1120.  
  1121.  
  1122. 7.16.  PS1
  1123. The PS1 environment variable contains the current prompt string, default for
  1124. super user login is '@# ', default for any other login is '@% '. It cannot be
  1125. unset.
  1126.  
  1127.  
  1128. 7.17.  PS2
  1129. The PS2 environment variable contains the prompt string for a continued
  1130. command line, e.g. within quotes or within a do loop; default is '> '. It
  1131. cannot be unset.
  1132.  
  1133.  
  1134. 7.18.  PS3
  1135. The PS3 environment variable contains the prompt string for input as part of
  1136. the 'select' language construct; default is '#? '. It cannot be unset.
  1137.  
  1138.  
  1139. 7.19.  PWD
  1140. The PWD environment variable contains the current data directory and is
  1141. automatically updated when a 'cd' or a 'chd' command is executed. This
  1142. functionality is identical to the CWD environment variable. If PWD, however,
  1143. is already set when 'sh' for OS-9 is started, it is - in contrast to CWD - not
  1144. considered. The PWD environment variable is read-only and cannot be unset.
  1145.  
  1146.  
  1147. 7.20.  SHDEBUG
  1148. The SHDEBUG environment variable forces the '-d' (debug) option to be set on
  1149. all dependent 'sh' calls. The debug option is disabled when SHDEBUG is either
  1150. not set or set to '0', 'OFF' or 'off', it is enabled when set to a non-zero
  1151. value, to 'ON' or 'on'. SHDEBUG cannot be unset.
  1152.  
  1153.  
  1154. 7.21.  SH_VERSION
  1155. The SH_VERSION environment variable contains the edition number of the
  1156. currently running instance of 'sh'. It can neither be unset nor set to another
  1157. value. If, for example, a script relies on a particular feature that is only
  1158. available from edition 142 onwards, the following command sequence may be
  1159. used:
  1160.  
  1161.        required=142
  1162.        if test -z $SH_VERSION || test $SH_VERSION -lt $required
  1163.        then
  1164.          if test -z $SH_VERSION
  1165.          then
  1166.            echo Current shell is too old
  1167.          else
  1168.            echo Current shell is edition $SH_VERSION
  1169.          fi
  1170.          echo Edition $required required
  1171.          echo Please upgrade
  1172.          exit 1
  1173.        fi
  1174.  
  1175.  
  1176.  
  1177. 8.     Built-in commands
  1178. ------------------------
  1179.  
  1180. 8.1.   . <file>
  1181. Read and execute commands from <file>. This command is similar to the
  1182. 'profile' command of the Mware shell; if compatibility is an issue, the line
  1183.  
  1184.       alias profile .
  1185.  
  1186. may be added to one of the initialization scripts ('.login', '/dd/SYS/profile'
  1187. or '.profile').
  1188.  
  1189.  
  1190. 8.2.   :
  1191. Does nothing. A zero exit code is returned.
  1192.  
  1193.  
  1194. 8.3.   [
  1195. This command is merely a synonym for 'test'. In contrast to 'test', however,
  1196. end of the test condition may be marked using the ']' character. 
  1197.  
  1198.  
  1199. 8.4.   alias <new> <old>
  1200. This command allows to assign the action <old> to the newly defined string
  1201. <new>. The following is an example for useful alias settings that may be put
  1202. into the '/dd/SYS/profile' file:
  1203.  
  1204.        alias a alias
  1205.        alias chkdsk dcheck
  1206.        alias env printenv
  1207.        alias h history
  1208.        alias last 'chd $LWD'
  1209.        alias md makdir
  1210.        alias profile .
  1211.        alias rm del
  1212.        alias rmdir deldir
  1213.        alias sd srcdbg
  1214.        alias sy sysdbg
  1215.        alias type list
  1216.  
  1217. The command 'alias' without an argument lists the current contents of the
  1218. alias buffer on screen.
  1219.  
  1220.  
  1221. 8.5.   break [<level>]
  1222. The 'break' command unconditionally stops the execution of a 'for', 'while'
  1223. or 'until' loop. Execution is resumed after the end of loop level <level>;
  1224. a value of 1 refers to the current loop, 2 refers to to nextmost outer loop
  1225. etc. If 'break' is entered without argument, <level> defaults to 1.
  1226.  
  1227.  
  1228. 8.6.   builtin <builtin> [<args>]
  1229. Execute the shell built-in command <builtin> passing arguments <args>.
  1230. Required, if a function has the name of a built-in command, but the built-in
  1231. command needs to be executed within that function. 
  1232.  
  1233.  
  1234. 8.7.   cd [<dir>]
  1235. Make <dir> the current data directory. The CWD environment variable is also
  1236. set to <dir>, the LWD environment variable is set to the most recent data
  1237. directory. If 'cd' is entered wihout argument, the user's home directory is
  1238. made the current data directory. The command 'cd -' causes the most recent
  1239. data directory to become the current directory (same as 'cd $LWD').
  1240.  
  1241.  
  1242. 8.8.   chd [<dir>]
  1243. Make <dir> the current data directory. The CWD environment variable is also
  1244. set to <dir>, the LWD environment variable is set to the most recent data
  1245. directory. If 'chd' is entered wihout argument, the user's home directory is
  1246. made the current data directory. The command 'chd -' causes the most recent
  1247. data directory to become the current directory (same as 'chd $LWD').
  1248.  
  1249.  
  1250. 8.9.   chx <dir>
  1251. Make <dir> the current execution directory.
  1252.  
  1253.  
  1254. 8.10.  cls
  1255. Clear screen.
  1256.  
  1257.  
  1258. 8.11.  dirs
  1259. Display the current stack of remembered directories. The 'popd' command is
  1260. used to recall a particular directory, the 'pushd' command adds a new
  1261. directory to the stack or rearranges it.
  1262.  
  1263.  
  1264. 8.12.  continue [<level>]
  1265. The 'continue' statement branches to the beginning of a 'for', 'while' or
  1266. 'until' loop. Execution is resumed at the beginning of loop level <level>;
  1267. a value of 1 refers to the current loop, 2 refers to to nextmost outer loop
  1268. etc. If 'continue' is entered without argument, <level> defaults to 1.
  1269.  
  1270.  
  1271. 8.13.  echo [-b|-n|-r] <string1> [<string2> ... <stringn>]
  1272. Prints the strings to screen. Optionally carriage return is omitted (-r), one
  1273. carriage return is printed after every single string (-n), or backslash
  1274. processing of the string is disabled (-b). The latter is, for example, helpful
  1275. to display the current setting of the TERMCAP environment variable that
  1276. normally contains backslash characters.
  1277.  
  1278.  
  1279. 8.14.  enable [-n] [<builtin>]
  1280. This command allows to enable or to disable (-n) a shell built-in command so
  1281. that a disk command with the same name can be executed. If 'enable' is entered
  1282. without arguments, all shell built-in commands are displayed on screen
  1283. preceded by a '+' or a '-' sign, if the particular command is enabled or
  1284. disabled, respectively.
  1285.  
  1286.  
  1287. 8.15.  eval <cmd>
  1288. Evaluate a command and add the result to the shell's internal variable set;
  1289. useful to manipulate environment variables.
  1290.  
  1291.  
  1292. 8.16.  ex <cmd>
  1293. Execute command <cmd> and leave the current shell.
  1294.  
  1295.  
  1296. 8.17.  exec <cmd>
  1297. Same as ex (see above).
  1298.  
  1299.  
  1300. 8.18.  exit [<code>]
  1301. Stop execution of 'sh' and return to the previous program. The return value
  1302. may be specified explicitly in the <code> argument; it defaults to zero,
  1303. otherwise.
  1304.  
  1305.  
  1306. 8.19.  export <name1>[=<value1>] [<name2>=[<value2>] ... <namen>=[<valuen>]]
  1307. The specified names are registered for automatic export to the environment of
  1308. subsequently executed commands. A list of all exported variables is produced
  1309. when 'export' is entered without arguments. In addition, a new value may be
  1310. assigned to the variable, if immediately followed by an equal sign and a
  1311. value, e.g.
  1312.  
  1313.        export NEWENV=newval
  1314.  
  1315.  
  1316. 8.20.  false
  1317. Returns the boolean value false for condition constructs such as 'while' or
  1318. 'if'. 
  1319.  
  1320.  
  1321. 8.21.  history [<num>|read|save]
  1322. Display the current content of the history buffer, if <num> is not given;
  1323. set the length of the history buffer to <num> lines, otherwise. The contents
  1324. of the history buffer are written to the file '$HOME/.sh_history' when 'sh'
  1325. quits. They are read during initialisation of a login shell, but can also be
  1326. re-read later by using the 'history read' command. When 'history save' is
  1327. entered, the currents contents of the history buffer are written to
  1328. '/$HOME/.sh_history' in the same way as when 'sh' quits.
  1329.  
  1330.  
  1331. 8.22.  kill [-<signal>] [-signal=<signal>] <proc1> [<proc2 ... <procn>]
  1332. Send signal <signal> (default 0) to the process or processes specified as
  1333. arguments. The argument may be given as process ID or as module name of the
  1334. requested process. If the name specifies a module that runs more than once, a
  1335. message a displayed and the user is given the choice to kill all or none of
  1336. the processes. Note that the kill signal (signal 0) cannot be caught nor
  1337. ignored.
  1338.  
  1339.  
  1340. 8.23.  logon
  1341. Invoke a new logon procedure, pass the current environment and abandon the
  1342. current process. In a first attempt, the program 'logon' is executed; if this
  1343. fails, 'login' is tried. 
  1344.  
  1345.  
  1346. 8.24.  logout [nohist]
  1347. Execute '$HOME/.logout' and '/dd/SYS/sh.logout', stop execution of 'sh' and
  1348. return to the previous program. If history is enabled and the optional
  1349. 'nohist' argument is not specified, the contents of the history buffer are
  1350. written to the file '$(HOME)/.sh_history'. If the '-l' option is not
  1351. enabled, entering the end-of-file character from the terminal path options
  1352. (normally escape) also causes 'sh' to logout.
  1353.  
  1354.  
  1355. 8.25.  NO
  1356. This command is only effective, if followed by 'CARRIER' in which case the
  1357. entire command is synonymous to 'logout'. Intended to correctly handle a
  1358. situation when the carrier is lost in a modem connection but the serial
  1359. interface is not able to detect changes in the DCD line.
  1360.  
  1361.  
  1362. 8.26.  pd [-x]
  1363. Display current data directory; the current execution directory is shown
  1364. instead, if the '-x' option is specified. Same as 'pwd'.
  1365.  
  1366.  
  1367. 8.27.  popd [+n]
  1368. Removes the entry n from the directory stack. If 'popd' is entered wihout
  1369. argument, the top directory is removed from the stack and made the current
  1370. data directory.
  1371.  
  1372.  
  1373. 8.28.  printenv [<var1> <var2> ... <varn>]
  1374. Print all (exportable ) environment variables. This command also excepts a
  1375. single argument or several ones that are output, one per line, in the
  1376. specified order. Unavailable variables are silently ignored.
  1377.  
  1378.  
  1379. 8.29.  pushd [dir] | [+n]
  1380. Adds a directory to the top of the directory stack, if [dir] is a valid
  1381. directory; otherwise, the directory stack is rotated until the nth element of
  1382. the directory stack is at top. If 'pushd' is entered without argument, the top
  1383. two directories are exchanged. After the rearrangement of the stack, the top
  1384. directory is always made the current data directory.
  1385.  
  1386.  
  1387. 8.30.  pwd [-x]
  1388. Display current data directory; the current execution directory is shown
  1389. instead, if the '-x' option is specified. Same as 'pd'.
  1390.  
  1391.  
  1392. 8.31.  read <var1> [<var2> ... <varn>]
  1393. The 'read' command reads a string that is entered at the keyboard into a
  1394. single variable or into several variables. If a single variable is specified,
  1395. whitespace is maintained; if several variables are specified, whitespace is
  1396. ignored and the separated input tokens are assigned to the variables in the
  1397. given order. The read command returns 0 in case of no error; it returns 1,
  1398. if end-of-file (normally Escape) is received. A value of 2 or 3 is returned,
  1399. if keyboard quit or keyboard abort was entered, respectively. Should a signal
  1400. be received during the read command, the number of the signal is returned.
  1401. If the '-l' option is set, end-of-file can be entered by hitting the
  1402. end-of-file character twice. The read command is the only shell built-in that
  1403. is able to receive input from a pipe, e.g.
  1404.  
  1405.        procs -e | grep myprog | read id pid grpusr prio memsiz
  1406.  
  1407. This makes it possible to easily realize a simple string parser.
  1408.  
  1409.  
  1410. 8.32.  readonly <name1>[=<value1>] [<name2>=[<value2>] ... <namen>=[<valuen>]]
  1411. Make the variable specified as argument read-only. Any shell variable
  1412. including environment variables can be passed as argument. If, for example,
  1413. the TERM variable is intended to be protected against unintentional changes,
  1414. the command
  1415.  
  1416.        readonly TERM
  1417.  
  1418. can be used. Any attempt to assign another value to the TERM environment
  1419. variable will then result in an error message. In addition, a new value may be
  1420. assigned to the variable, if immediately followed by an equal sign and a
  1421. value, e.g.
  1422.  
  1423.        readonly PROTECTVAL=safe
  1424.  
  1425.  
  1426. 8.33.  return [<val>]
  1427. A function exits and, optionally, returns the value <val>.
  1428.  
  1429.  
  1430. 8.34.  set <var1> [<var2> ... <varn>]
  1431. This command is used to set shell command arguments in the same way, as if they
  1432. had been entered when starting the shell. This includes options and other
  1433. arguments, but they cannot be mixed. If the first argument to the 'set'
  1434. command starts with the '-' character, all following strings are considered
  1435. options; they are taken as arguments, otherwise. To inhibit the login
  1436. procedure when the escape character is entered, the command
  1437.  
  1438.        set -l
  1439.  
  1440. can, for example, be used. If 'set' is entered without arguments, a list of
  1441. all currently defined environment variables, shell variables and functions is
  1442. produced. Finally, 'set -' can be entered in which case all flags except the
  1443. '-l' flag will be set to their defaults.
  1444.  
  1445.  
  1446. 8.35.  setenv <variable> <value>
  1447. Define the environment <variable> and assign <value> to it. In contrast to the
  1448. assignment command '<variable>=<value>', the 'setenv' command implicitly sets
  1449. the variable attribute to 'export' so that it is automatically exported when a
  1450. child process is forked. 
  1451.  
  1452.  
  1453. 8.36.  setpr [<pid> <priority>] [<priority>]
  1454. Set the priority of the process with the process ID <pid> to <priority>. 
  1455. Alternatively, the default priority for future forks can be set. If 'setpr' is
  1456. entered without arguments, the current default process priority is displayed
  1457. on screen.
  1458.  
  1459.  
  1460. 8.37.  setstack [<stack>]
  1461. Set the additional data stack to <stack> kByte when forking a program. If
  1462. 'setstack' is entered without arguments, the current additional data stack
  1463. size is displayed on screen.
  1464.  
  1465.  
  1466. 8.38.  setuid <group.user> | <name>
  1467. Set the shell's group and user ID; can only be executed, if the shell process
  1468. is owned by a member of the super user group.
  1469.  
  1470.  
  1471. 8.39.  shift <n>
  1472. The positional parameters from <n+1> etc. are renamed to $1 etc. If <n> is not
  1473. given, 1 is assumed. The 'shift' command is useful for command line parsing.  
  1474.  
  1475.  
  1476. 8.40.  show
  1477. All shell variables including environment variables are displayed on screen.
  1478.  
  1479.  
  1480. 8.41.  suspend [<signal>]
  1481. The shell is suspended until the signal <signal> is received. Any activity is
  1482. suspended except that traps for other signals (installed using the 'trap
  1483. <command> <number>' command) are executed. If <signal> is not specified, any
  1484. signal will restart the shell.
  1485.  
  1486.  
  1487. 8.42.  test <opt1> <arg1> <opt2> [<arg2>] 
  1488. The 'test' command is used to perform a number of unary tests and binary
  1489. comparisons; it returns true, if one of the following options is specified
  1490. and the respective condition is true:
  1491.  
  1492.        Paths, descriptors and modules:
  1493.        -b          arg1 is a block device descriptor (RBF/NFS, SBF, CDFM)
  1494.        -d          arg1 is an existing path and is a directory
  1495.        -f          arg1 is an existing path
  1496.        -h          always returns false (Unix: <arg1> is a symbolic link)
  1497.        -L          always returns false (Unix: <arg1> is a symbolic link)
  1498.        -m          arg1 is an existing memory module
  1499.        -p          arg1 is an existing path and is a named pipe
  1500.        -r          arg1 is an existing path and is readable
  1501.        -s          arg1 is an existing path and has a size greater than zero
  1502.        -t          arg1 is an existing path open to a terminal
  1503.        -w          arg1 is an existing path and is writable
  1504.        -x          arg1 is an existing path and is an executable file
  1505.  
  1506.        Strings:
  1507.        -z          arg1 is an empty string
  1508.        -n          arg1 is a non-empty string
  1509. <arg1> = <arg2>    true if string <arg1> equals string <arg2>
  1510. <arg1> != <arg2>   true if string <arg1> is not equal string <arg2>
  1511.  
  1512.        Integers:
  1513.        -eq         true if integer <arg1> equals integer <arg2>
  1514.        -ne         true if integer <arg1> is not equal integer <arg2>
  1515.        -ge         true if integer <arg1> is greater than or equal <arg2>
  1516.        -gt         true if integer <arg1> is greater than integer <arg2>
  1517.        -le         true if integer <arg1> is lower than or equal <arg2>
  1518.        -lt         true if integer <arg1> is lower than integer <arg2>
  1519.  
  1520.        Expressions:
  1521.        !<arg>      true if <arg> is false
  1522.        -a          true if both <arg1> and <arg2> are true
  1523.        -o          true if either <arg1> or <arg2> is true
  1524.  
  1525. Several logical conditions can be grouped together using parentheses. The
  1526. following condition, for example, would return true, if only 'file1' exists
  1527.  
  1528.        if test -f file1 -o ( -f file2 -a -f file3 )
  1529.  
  1530. while
  1531.  
  1532.        if test ( -f file1 -o -f file2 ) -a -f file3
  1533.  
  1534. would return false in such case. The first example could also have been written
  1535. without parentheses.
  1536.  
  1537.  
  1538. 8.43.  trap [<command> <number>]
  1539. Define an action to be executed when signal <number> is received; the command
  1540.  
  1541.        trap "echo 'You better NOT kill your shell...'" 2
  1542.  
  1543. will, for example, display the string 'You better NOT kill your shell...' when
  1544. Cntrl-E is entered from the keyboard. A trap can be removed from a signal by
  1545. entering 'trap' followed just by that signal number. If 'trap' is entered
  1546. without arguments, a list of all currently trapped signals is produced.
  1547.  
  1548.  
  1549. 8.44.  true
  1550. Returns the boolean value true for condition constructs such as 'while' or
  1551. 'if'. 
  1552.  
  1553.  
  1554. 8.45.  tty [<devno>]
  1555. Return the name of the path number <devno>. If not specified, <devno> defaults
  1556. to 0.
  1557.  
  1558.  
  1559. 8.46.  umask [<mask> | <attr>]
  1560. Return the current file creation mode mask for files created by 'sh', if
  1561. entered without arguments (default modes are owner read and owner write). A
  1562. new file creation mode mask may be entered using the octal number <mask>; bits
  1563. that are set in the mask are cleared in the modes of created files.
  1564. Alternatively, new file modes may be entered as they were arguments to the
  1565. OS-9 utility 'attr'. Only owner read/write and public read/write modes can be
  1566. set or cleared.  
  1567.  
  1568.  
  1569. 8.47.  unalias <alias>
  1570. Undefine the string previously assigned to <alias>.
  1571.  
  1572.  
  1573. 8.48.  unset [-f] <function> | <variable>
  1574. Make a previously defined function ('-f' option) undefined. If the '-f' option
  1575. is not specified, 'unset' is identical to 'unsetenv' except that no error is
  1576. generated, if an attempt is made to unset a non-existing variable.
  1577.  
  1578.  
  1579. 8.49.  unsetenv <variable>
  1580. Make a previously defined environment or shell variable undefined.
  1581.  
  1582.  
  1583. 8.50.  version [<help>]
  1584. Display 'sh' version, edition and compilation date. The argument <help> may be
  1585. any of 'c(ommands)', 'k(eycaps)', 'l(anguage)', or 't(est)' to display a
  1586. listing of available shell built-in commands, keycap settings, language
  1587. construct elements, or test functions, respectively. A '+' or '-' sign that
  1588. precedes the name of a shell built-in command indicates whether that particular
  1589. command is currently enabled or not.
  1590.  
  1591.  
  1592. 8.51.  w
  1593. Suspend 'sh' until any one child process terminates and return its termination
  1594. status.
  1595.  
  1596.  
  1597. 8.52.  wait [<pid>]
  1598. Suspend 'sh' until the process with process ID <pid> has finished and return
  1599. its termination status. If no argument is specified, 'sh' waits until all
  1600. child processes have finished, in which case the return value is always zero.
  1601.  
  1602.  
  1603.  
  1604. 9.     Language construct elements
  1605. ----------------------------------
  1606.  
  1607. 9.1.   for <var> [in <val1> <val2> ... <valn>]
  1608. The 'for' construct is used to execute loops in shell scripts; every time
  1609. the subsequent do .. done segment is executed, <var> will be set to <val1>,
  1610. <val2>, until <valn> is reached. If, for example, library files have to be
  1611. scanned for the occurrence of a specific function, the commands
  1612.  
  1613.        for i in /h0/LIB/*.l
  1614.        do
  1615.          echo Scanning $i:
  1616.          rdump $i -a | grep function
  1617.        done  
  1618.  
  1619. may be entered. Shell arguments are used as variable values, if the 'in'
  1620. language construct element is omitted.
  1621.  
  1622.  
  1623. 9.2.   select <var> [in <val1> <val2> ... <valn>]
  1624. The 'select' construct is intended to let the user select from a list of
  1625. values; every value is labeled by a consecutive number starting from 1. The
  1626. selected item is assigned to <var> during execution of the subsequent do ..
  1627. done segment until a 'break' command is encountered or until the user has
  1628. entered EOF condition. An empty string is assigned to <var>, if an invalid
  1629. selection is made. The string contained in the environment variable PS3 is
  1630. displayed after the variable list. The following example lets the user select
  1631. a directory from the PATH environment variable:
  1632.  
  1633.        PS3='Execution directory? '
  1634.        select dir in `echo $PATH | tr ':' ' '`
  1635.        do
  1636.          if [ $dir ]
  1637.          then
  1638.            echo You selected directory $dir
  1639.            break
  1640.          fi  
  1641.        done
  1642.  
  1643. It will, for example, ask for a selection
  1644.  
  1645.        1) .
  1646.        2) /dd/USR/CMDS
  1647.        3) /dd/ETC/CMDS
  1648.        4) /dd/CMDS
  1649.        Execution directory?
  1650.  
  1651. and, if '2' is entered, display
  1652.  
  1653.        You selected directory /dd/USR/CMDS
  1654.  
  1655.  
  1656. 9.3.   while [!] <condition>
  1657. The do .. done segment that follows the 'while' language construct element 
  1658. is executed repeatedly, until <condition> becomes false. Optionally,
  1659. <condition> may be preceded by the '!' operator in which case the sense of
  1660. <condition> is inverted. A program will, for example, rerun continuously,
  1661. if the commands
  1662.  
  1663.        while true
  1664.        do
  1665.          program
  1666.        done
  1667.  
  1668. are entered. Such a command sequence may be useful to exhibit software at a
  1669. fair.
  1670.  
  1671.  
  1672. 9.4.   case <var> in
  1673. The 'case' construct is used to select among several conditions. A simple
  1674. user interface to delete or not a particular file in the current data
  1675. directory can, for example, be written as
  1676.  
  1677.        for i in *
  1678.        do
  1679.          echo Delete file $i?
  1680.          read response
  1681.          case $response in
  1682.            y*) del $i ;;
  1683.            n*) ;;
  1684.            q*) break
  1685.          esac
  1686.        done
  1687.  
  1688. The match condition may contain the '|' (or) symbol to indicate that several
  1689. conditions may match, e.g. 'y*|Y*)'. 
  1690.  
  1691.  
  1692. 9.5.   esac
  1693. The 'esac' language construct element is a component of the 'case' construct,
  1694. see above.
  1695.  
  1696.  
  1697. 9.6.   do
  1698. The 'do' construct is a component of the 'for', 'select', 'until' and 'while'
  1699. constructs, see above and below.
  1700.  
  1701.  
  1702. 9.7.   done
  1703. The 'done' language construct element is a component of the 'for', 'select',
  1704. 'until' and 'while' constructs, see above and below.
  1705.  
  1706.  
  1707. 9.8.   if [!] <condition>
  1708. The 'if' construct is used to execute one or several shell commands based upon
  1709. the return value of <condition>. Optionally, <condition> may be preceded by
  1710. the '!' operator in which case the sense of <condition> is inverted. Standard
  1711. evaluation programs such as 'cmp', 'diff' or 'grep' normally return 0 or 1, if
  1712. the program's action fails or not, respectively. The following shell script
  1713. can, for example, be used to copy only those files from /h0/CMDS to
  1714. /h0/DISK1/CMDS that already exist on /h0/DISK1/CMDS but are different. 
  1715.  
  1716.        cd /h0/DISK1/CMDS
  1717.        dir=/h0/CMDS
  1718.        for i in *
  1719.          do
  1720.          if cmp $dir/$i $i -u
  1721.          then
  1722.            echo $dir/$i is the same as $i
  1723.          else
  1724.            echo $dir/$i is DIFFERENT from $i
  1725.            copy $dir/$i -rb=64
  1726.            echo $dir/$i copied to $i
  1727.          fi
  1728.        done
  1729.  
  1730.  
  1731. 9.9.   in
  1732. The 'in' language construct element may optionally be used as part of the
  1733. 'for' loop, see above.
  1734.  
  1735.  
  1736. 9.10.  then
  1737. The 'then' language construct element is a required component of the 'if'
  1738. and the 'elif' statements, see above.
  1739.  
  1740.  
  1741. 9.11.  else
  1742. The 'else' language construct element may optionally be used within the 'if'
  1743. construct, see above.
  1744.  
  1745.  
  1746. 9.12.  elif [!] <condition>
  1747. The 'elif' language construct element stands for 'else if' and may optionally
  1748. be used within the 'if' construct, see above. Optionally, <condition> may be
  1749. preceded by the '!' operator in which case the sense of <condition> is
  1750. inverted.
  1751.  
  1752.  
  1753. 9.13.  until [!] <condition>
  1754. The do .. done segment that follows the 'until' language construct element
  1755. is executed repeatedly, as long as <condition> is false. Optionally,
  1756. <condition> may be preceded by the '!' operator in which case the sense of
  1757. <condition> is inverted.
  1758.  
  1759.  
  1760. 9.14.  fi
  1761. The 'fi' language construct element terminates 'if' and 'elif' constructs, see
  1762. above.
  1763.  
  1764.  
  1765. 9.15.  ;;
  1766. The ';;' language construct element terminates a selection as part of the case
  1767. construct, see above. 
  1768.  
  1769.  
  1770. 9.16.  <condition> || [!] <condition>
  1771. OR operator for condition constructs following 'if', 'elif', 'while' and
  1772. 'until'. Optionally, <condition> may be preceded by the '!' operator in which
  1773. case the sense of <condition> is inverted. In addition, the OR operator may be
  1774. placed between two commands; the second command is then only executed, if the
  1775. first one returns false:
  1776.  
  1777.        false || echo second command is being executed
  1778.        true  || # NEVER REACHED
  1779.  
  1780.  
  1781. 9.17.  <condition> && [!] <condition>
  1782. AND operator for condition constructs following 'if', 'elif', 'while' and
  1783. 'until'. Optionally, <condition> may be preceded by the '!' operator in which
  1784. case the sense of <condition> is inverted. In addition, the AND operator may
  1785. be placed between two commands; the second command is then only executed, if
  1786. the first one returns true:
  1787.  
  1788.        true  && echo second command is being executed
  1789.        false && # NEVER REACHED
  1790.  
  1791.  
  1792. 9.18   (
  1793. Start an independent subshell to execute the commands in parentheses. The
  1794. return value is that of the last executed command:
  1795.  
  1796.        echo main shell is shell number $_sh
  1797.        (echo subshell is shell number '$_sh')
  1798.  
  1799.  
  1800. 9.19.  )
  1801. Selects a condition within a case statement. The condition may contain the
  1802. '*' wildcard character; in addition, the '|' character may be used to indicate
  1803. that one of several conditions may match.
  1804.  
  1805.  
  1806. 9.20.  <name> () { <command1> [<command2>] .. [<commandn>] }
  1807. Define the shell function <name>. Any commands that may legally be typed from
  1808. shell prompt may also appear within a command. End of function is assumed and
  1809. the function is internally stored and assigned to <name>, when the '}'
  1810. character is reached. The function can be executed just by entering its name;
  1811. it may be inspected by using the 'set' command without arguments. Any number
  1812. of arguments may be passed to the function; they are recalled within the
  1813. function using the '$<n>' syntax. A function may return a value using the
  1814. 'return <val>' syntax. The return value may be inspected using the '$?' syntax
  1815. or directly examined in a 'test' statement. Recursive calls to a function are
  1816. allowed. An example for a shell function is given in section 10.4.
  1817.  
  1818.  
  1819. 9.21.  !
  1820. The '!' language construct element stands for 'not' and may appear after 'if',
  1821. 'elif', 'while', 'until', '||' or '&&'. It inverts the return value of the
  1822. subsequent logical condition.
  1823.  
  1824.  
  1825.  
  1826. 10.    Constants
  1827. ----------------
  1828.  
  1829. 10.1.  Input buffer from command line
  1830. Initial buffer size is 2048 characters, it is expanded dynamically until the
  1831. system's memory is exhausted.
  1832.  
  1833. 10.2.  Input buffer from shell script
  1834. Initial buffer size is 2048 characters, it is expanded dynamically until the
  1835. system's memory is exhausted.
  1836.  
  1837. 10.3.  Input buffer of built-in read command
  1838. Initial buffer size of the input line during the built-in read command is
  1839. 2048 characters, it is expanded dynamically until the system's memory is
  1840. exhausted.
  1841.  
  1842. 10.4.  Input buffer for a syntactical element
  1843. Initial buffer size for a syntactical element (command, function, alias etc.)
  1844. is 507 characters, it is expanded dynamically until the system's memory is
  1845. exhausted.
  1846.  
  1847. 10.5.  Maximum nesting depth 
  1848. Commands may not be nested more deeply than 8 levels.
  1849.  
  1850. 10.6.  Maximum number of history lines
  1851. The number of history lines is limited to 500.
  1852.  
  1853. 10.7.  Maximum length of history match string
  1854. The string length of a history match string may not exceed 127 characters.
  1855.  
  1856. 10.8.  Maximum number of aliases
  1857. The number of aliases is limited to 100.
  1858.  
  1859. 10.9.  Maximum length of alias string
  1860. The string length of an alias string may not exceed 127 characters.
  1861.  
  1862. 10.10. Default pipe length
  1863. Pipes for the communication between concurrently executing programs have a
  1864. default length of 512 Bytes. If the output of a shell built-in command is 
  1865. redirected into a pipe, its size is set dynamically.
  1866.  
  1867. 10.11. Signal numbers that may be trapped
  1868. Only signals with a number between #1 and #63 may be trapped. 
  1869.  
  1870. 10.12. Size of paste buffer
  1871. The internal paste buffer ("Clear to end of line", "Delete current line",
  1872. "Abandon edit line", "Word delete") has a size of 255 characters.
  1873.  
  1874. 10.13. Signals
  1875. Whenever 'sh' receives signal #4 (SIGHUP), signal #10 (former SIGTERM) or
  1876. signal #36 (SIGTERM) and the signal's default action has not been disabled
  1877. using the 'trap' command, 'sh' immediately stops execution and returns the
  1878. respective signal number.
  1879.  
  1880.  
  1881.  
  1882. 11.    Important features
  1883. -------------------------
  1884.  
  1885. 11.1.  Name completion
  1886. The TAB key (or the key specified by the 'ta' termcap entry) causes 'sh' to
  1887. match the already entered string as a command (command name completion), as a
  1888. file or directory name (file name completion), as a shell variable (variable
  1889. name completion) or as a user (user name completion). If, for example, the
  1890. name of the first of the two files
  1891.  
  1892.        thisfilehasaverylongname1
  1893.        thisfilehasaverylongname2
  1894.  
  1895. in the current directory is required, is it sufficient to enter
  1896.  
  1897.        t<TAB>1
  1898.  
  1899. If the completion key is entered twice
  1900.  
  1901.        t<TAB><TAB>
  1902.        thisfilehasaverylongname1 thisfilehasaverylongname2
  1903.        t
  1904.  
  1905. a list of all available files is displayed on screen and the original input
  1906. line repeated below this list so that editing can be continued immediately.
  1907.  
  1908.  
  1909. 11.2.  Regular expressions
  1910. Regular expressions are evaluated whenever a string is entered. If, for
  1911. example, all files that have 'a', 'b', or 'c' as first character are to be
  1912. deleted, the command
  1913.  
  1914.        del [abc]*
  1915.  
  1916. will do the job. Alternatively, the command
  1917.  
  1918.        del [a-c]*
  1919.  
  1920. can be entered for this purpose. The regular expression is also considered
  1921. for file name completion. If the first character after the '[' symbol is the
  1922. exclamation mark ('!') or the caret symbol ('^'), the sense of the comparison
  1923. is inverted, i.e. only strings that do NOT match the character class are
  1924. considered.
  1925.  
  1926.  
  1927. 11.3.  Availability of environment variables
  1928. All environment variables are available in a command when preceded by the '$'
  1929. sign. Inspecting the current setting of the TERM environment variable is, for
  1930. example, done by entering the
  1931.  
  1932.        echo $TERM
  1933.  
  1934. command; adding the directory '/h0/BIN' to the PATH environment variable can
  1935. simply be done by entering the
  1936.  
  1937.        setenv PATH $PATH:/h0/BIN
  1938.  
  1939. command.
  1940.  
  1941.  
  1942. 11.4.  Shell functions
  1943. Shell functions can easily be created and executed. This can be done from
  1944. prompt level but functions may also be part of an 'sh' script. Programming
  1945. an 'sh' script that makes use of functions is somewhat similar to writing a
  1946. program in the C language. Any number of arguments may be passed to the
  1947. function; they are recalled within the function using the '$<n>' syntax. The
  1948. following 'sh' script may serve as an example:
  1949.  
  1950.        func1() {
  1951.          echo Executing function 1.
  1952.          if [ $4 ]
  1953.          then
  1954.            echo $1 $2 $3 $4.
  1955.            return 0
  1956.          fi
  1957.          return 1
  1958.        }
  1959.  
  1960.        func2() {
  1961.          echo Executing function 2.
  1962.          if [ $4 ]
  1963.          then
  1964.            echo $1 $2 $3 $4.
  1965.            return 0
  1966.          fi
  1967.          return 2
  1968.        }
  1969.  
  1970.        if test $# -eq 0
  1971.        then
  1972.          echo "Please use one of 'f1' or 'f2' as first argument." 1>&2
  1973.          echo "Optionally, a second argument can be specified." 1>&2
  1974.          exit 1
  1975.        fi
  1976.  
  1977.        if test $1 = "f1"
  1978.        then
  1979.          if func1 Command line argument $2 
  1980.          then
  1981.            echo Arguments printed.
  1982.          else
  1983.            echo Function $? executed.
  1984.          fi
  1985.          exit 0
  1986.        fi
  1987.  
  1988.        if test $1 = "f2"
  1989.        then
  1990.          if func2 Command line argument $2
  1991.          then
  1992.            echo Arguments printed.
  1993.          else
  1994.            echo Function $? executed.
  1995.          fi
  1996.          exit 0
  1997.        fi
  1998.  
  1999.        echo Illegal argument \'"$1"\' 1>&2
  2000.        exit 1
  2001.  
  2002.  
  2003.  
  2004. 12.    Compatibility between 'sh' and 'shell'
  2005. ---------------------------------------------
  2006.  
  2007. All main syntax elements are compatible between 'sh' and 'shell'. There are
  2008. only a few remaining differences.
  2009.  
  2010. 12.1.  Redirected output overwrites file
  2011.        In contrast to the Mware shell, 'sh' overwrites files to which output
  2012.        is redirected. The behavior of the Mware shell can, however, be
  2013.        simulated by specifying the '-C' command line option. 
  2014.  
  2015. 12.2.  Handling of unmatched wildcards
  2016.        'sh' passes wildcard symbols to the called program, if they do not
  2017.        match. The Mware shell writes the message "Wildcard match failed
  2018.        for command '<cmd>'" in such a case and does not call the program.
  2019.  
  2020. 12.3.  Built-in command 'set' requires a hyphen for option setting
  2021.        Hyphens cannot be omitted when specifying options in the 'set' command,
  2022.        since 'sh' uses the hyphen to distinguish options from arguments.
  2023.  
  2024. 12.4.  Search order for programs and scripts
  2025.        Both Mware shells 'shell' and 'mshell' search the current execution
  2026.        directory prior to the directories specified in the PATH environment
  2027.        variable, whereas 'sh' uses a more flexible approach and first examines
  2028.        the PATH variables and then the current execution directory. Mware's
  2029.        search order may be forced by specifying the current execution
  2030.        directory as the first element in the PATH environment variable.
  2031.  
  2032.  
  2033.  
  2034. 13.    To do
  2035. ------------
  2036.  
  2037. 13.1.  TAB name completion and cursor position
  2038.        TAB name completion only works, if the cursor is at the end of the
  2039.        input line.
  2040.  
  2041. 13.2.  Interrupting execution of '.' command 
  2042.        When keyboard interrupt or keyboard abort is hit during execution of
  2043.        a script in the current sh environment (. <file>) sh exits. Would be
  2044.        preferable, if only execution of the script were stopped. 
  2045.  
  2046.  
  2047.  
  2048. 14.    References
  2049. -----------------
  2050.  
  2051. 14.1.  Kernighan BW, Pike R (1984): The UNIX programming environment.
  2052.        Prentice-Hall, Englewood Cliffs, NY. ISBN 0-13-937699-2.
  2053.  
  2054. 14.2.  Bourne SR (1987): The UNIX System V environment.
  2055.        Addison-Wesley, Reading, MA. ISBN 0-201-18484-2.
  2056.  
  2057. 14.3.  Newham C, Rosenblatt B (1995): Learning the bash shell.
  2058.        O'Reilly, Sebastopol, CA. ISBN 1-56592-147-X.
  2059.