home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / man / man1 / sh.1 < prev    next >
Encoding:
Text File  |  1975-06-26  |  9.5 KB  |  339 lines

  1. .th SH I 5/15/74
  2. .sh NAME
  3. sh  \*-  shell (command interpreter)
  4. .sh SYNOPSIS
  5. .bd sh
  6. [
  7. .bd \*-t
  8. ] [
  9. .bd \*-c
  10. ]
  11. [ name [ arg1 ... [ arg9 ] ] ]
  12. .sh DESCRIPTION
  13. .it Sh
  14. is the standard command interpreter.
  15. It is the program which reads and arranges the execution of
  16. the command lines typed by most users.
  17. It may itself be called as a command to interpret
  18. files of commands.
  19. Before discussing the arguments to the Shell
  20. used as a command, the structure of command
  21. lines themselves will be given.
  22. .s3
  23. .bd "Commands."
  24. Each command is a sequence of non-blank command arguments
  25. separated by blanks.
  26. The
  27. first argument specifies the name of a command to be
  28. executed.
  29. Except for certain types of special
  30. arguments discussed below, the arguments
  31. other than the command name are passed
  32. without interpretation to the invoked
  33. command.
  34. .s3
  35. If the first argument is the name of an executable
  36. file, it is invoked;
  37. otherwise the string `/bin/' is prepended to the argument.
  38. (In this way most standard commands,
  39. which reside in `/bin', are found.)
  40. If no such command is found,
  41. the string `/usr' is further prepended
  42. (to give `/usr/bin/command') and another attempt
  43. is made to execute the resulting
  44. file.
  45. (Certain lesser-used commands
  46. live in `/usr/bin'.)
  47. .s3
  48. If a non-directory file has executable mode,
  49. but not the form of an executable program
  50. (does not begin with the proper magic number)
  51. then it is assumed to be an ASCII file of commands
  52. and a new Shell is created to execute it.
  53. See ``Argument passing'' below.
  54. .s3
  55. If the file cannot be found,
  56. a diagnostic is printed.
  57. .s3
  58. .bd "Command lines."
  59. One or more commands separated by `|' or `^' constitute a
  60. chain of
  61. .it filters.
  62. The standard output of each command but the last
  63. is taken
  64. as the standard input of the next command.
  65. Each command is run as a separate process, connected
  66. by pipes (see pipe(II)) to its neighbors.
  67. A command line contained in
  68. parentheses `( )' may appear in place of a simple command
  69. as a filter.
  70. .s3
  71. A
  72. .it "command line"
  73. consists of one or
  74. more pipelines separated, and perhaps terminated by `\fB;\fR' or `&'.
  75. The semicolon designates sequential execution.
  76. The ampersand causes the preceding pipeline to be executed
  77. without waiting for it to finish.
  78. The process id of such a pipeline is reported, so that
  79. it may be used if necessary for a subsequent
  80. .it wait
  81. or
  82. .it kill.
  83. .s3
  84. .bd "Termination Reporting."
  85. If a command (not followed by `&') terminates abnormally,
  86. a message is printed.
  87. (All terminations other than exit and interrupt
  88. are considered abnormal.)
  89. Termination reports for commands followed by `&'
  90. are given upon receipt of the first
  91. command subsequent to the termination of
  92. the command,
  93. or when a
  94. .it wait
  95. is executed.
  96. The following is a list of the abnormal
  97. termination messages:
  98. .s3
  99. .nf
  100.     Bus error
  101.     Trace/BPT trap
  102.     Illegal instruction
  103.     IOT trap
  104.     EMT trap
  105.     Bad system call
  106.     Quit
  107.     Floating exception
  108.     Memory violation
  109.     Killed
  110.     Broken Pipe
  111. .s3
  112. .fi
  113. If a core image is produced,
  114. `\*- Core dumped' is appended to the appropriate message.
  115. .s3
  116. .bd "Redirection of I/O."
  117. There are three character sequences that cause the immediately following string
  118. to be interpreted as a special argument to the Shell itself.
  119. Such an argument may
  120. appear anywhere among
  121. the arguments of a simple command, or before or after
  122. a parenthesized command list, and is associated with that
  123. command or command list.
  124. .s3
  125. An argument of the form `<arg' causes the file
  126. `arg'
  127. to be used as the standard input (file descriptor 0) of the associated command.
  128. .s3
  129. An argument of the form `>arg' causes file `arg' to be used
  130. as the standard output (file descriptor 1) for the associated command.
  131. `Arg' is created if it did not exist, and in any case is truncated
  132. at the outset.
  133. .s3
  134. An argument of the form `>>arg' causes file `arg' to be used as the
  135. standard output for the associated command.
  136. If `arg'
  137. did not exist, it is created; if it did exist,
  138. the command output is appended to the file.
  139. .s3
  140. For example, either of the command lines
  141. .s3
  142.     ls >junk; cat tail >>junk
  143. .br
  144.     ( ls; cat tail ) >junk
  145. .s3
  146. creates, on file `junk', a listing of the working directory, followed immediately
  147. by the contents of file `tail'.
  148. .s3
  149. Either of the constructs `>arg' or `>>arg'
  150. associated with any but the last command of a pipeline
  151. is ineffectual, as is `<arg' in any but the first.
  152. .s3
  153. In commands called by the Shell,
  154. file descriptor 2 refers to the standard output of the
  155. Shell before any redirection.
  156. Thus filters may write diagnostics
  157. to a location
  158. where they have a chance to be seen.
  159. .s3
  160. .bd "Generation of argument lists."
  161. If any argument contains any of the characters `?',
  162. `*' or `[', it is treated specially as follows.
  163. The current directory is searched for files which
  164. .it match
  165. the given argument.
  166. .s3
  167. The character `*' in an argument matches any string of characters
  168. in a file name (including the null string).
  169. .s3
  170. The character `?' matches any
  171. single character in a file name.
  172. .s3
  173. Square brackets `[...]' specify
  174. a class of characters which
  175. matches any single file-name character in the class.
  176. Within the brackets,
  177. each ordinary character is taken
  178. to be a member of the class.
  179. A pair of characters separated by `\*-' places
  180. in the class
  181. each character lexically greater than or equal to
  182. the first and less than or equal to the second
  183. member of the pair.
  184. .s3
  185. Other characters match only the same character in
  186. the file name.
  187. .s3
  188. For example, `*' matches all file names;
  189. `?' matches all one-character file names; `[ab]*.s' matches
  190. all file names beginning with `a' or `b' and ending with `.s';
  191. `?[zi\*-m]' matches all two-character file names ending
  192. with `z' or the letters `i' through `m'.
  193. .s3
  194. If the argument with `*' or `?' also contains a `/', a slightly
  195. different procedure is used:  instead of the current directory,
  196. the directory used is the one obtained
  197. by taking the argument up to the last `/' before a `*' or `?'.
  198. The matching process matches the remainder of the argument
  199. after this `/' against the files in the derived directory.
  200. For example: `/usr/dmr/a*.s' matches
  201. all files in directory `/usr/dmr' which begin
  202. with `a' and end with `.s'.
  203. .s3
  204. In any event, a list of names is obtained which match
  205. the argument.
  206. This list is sorted into alphabetical order,
  207. and the resulting sequence of arguments replaces the
  208. single argument containing the `*', `[', or `?'.
  209. The same process is carried out for each argument
  210. (the resulting lists are
  211. .it not
  212. merged)
  213. and finally the command is called with the resulting list of
  214. arguments.
  215. .s3
  216. .bd "Quoting."
  217. The character `\\' causes the immediately following character
  218. to lose any special meaning it may have to the Shell;  in this
  219. way `<', `>', and other characters meaningful to the
  220. Shell may be passed as part of arguments.
  221. A special case of this feature allows the continuation of commands
  222. onto more than one line:  a new-line preceded by `\\' is translated
  223. into a blank.
  224. .s3
  225. Sequences of characters enclosed in double (") or single (\*a)
  226. quotes are also taken literally.
  227. For example:
  228. .s3
  229.     ls  |  pr \*-h "My directory"
  230. .s3
  231. causes a directory listing to be produced
  232. by
  233. .it ls,
  234. and passed on to
  235. .it pr
  236. to be
  237. printed with the heading `My directory'.
  238. Quotes permit the inclusion of blanks in
  239. the heading, which is a single argument to
  240. .it pr.
  241. .s3
  242. .bd "Argument passing."
  243. When the Shell is invoked as a command, it has additional
  244. string processing capabilities.
  245. Recall that the form in which the Shell is invoked is
  246. .s3
  247.     sh [ name [ arg1 ... [ arg9 ] ] ]
  248. .s3
  249. The
  250. .it name
  251. is the name of a file which is read and
  252. interpreted.
  253. If not given, this subinstance of the Shell
  254. continues to read the standard input file.
  255. .s3
  256. In command lines in the file
  257. (not in command input),
  258. character sequences of the form `$n', where
  259. .it n
  260. is a digit,
  261. are replaced by the
  262. \fIn\fRth argument to the invocation
  263. of the Shell (argn).
  264. `$0' is replaced by
  265. .it name.
  266. .s3
  267. The argument `\*-t,' used alone, causes
  268. .it sh
  269. to read the standard input for a single line, execute
  270. it as a command, and then exit.
  271. This facility replaces the older `mini-shell.'
  272. It is useful for interactive programs
  273. which allow users to execute
  274. system commands.
  275. .s3
  276. The argument `\*-c' (used with one following argument)
  277. causes the next argument to be taken as a command
  278. line and executed.
  279. No new-line need be present, but new-line characters
  280. are treated appropriately.
  281. This facility is useful as an alternative to
  282. `\*-t' where the caller has already read
  283. some of the characters of the command to be executed.
  284. .s3
  285. .bd "End of file."
  286. An end-of-file in the Shell's input causes it to exit.
  287. A side effect of this fact means that the way to
  288. log out from UNIX is to type an EOT.
  289. .s3
  290. .bd "Special commands."
  291. The following commands are treated specially by the Shell.
  292. .s3
  293. .it chdir
  294. is done without
  295. spawning a new process by executing
  296. .it "sys chdir"
  297. (II).
  298. .s3
  299. .it login
  300. is done by executing
  301. /bin/login without creating a new process.
  302. .s3
  303. .it wait
  304. is done without spawning a new process by
  305. executing
  306. .it "sys wait"
  307. (II).
  308. .s3
  309. .it shift
  310. is done by manipulating the arguments
  311. to the Shell.
  312. .s3
  313. `\fB:\fR' is simply ignored.
  314. .s3
  315. .bd "Command file errors; interrupts."
  316. Any Shell-detected error, or an interrupt signal,
  317. during the execution of a command file
  318. causes the Shell to cease execution of that file.
  319. .s3
  320. Processes that are created with `&' ignore interrupts.
  321. Also if such a process has not redirected its
  322. input with a `<',
  323. its input is automatically redirected to the
  324. zero length file /dev/null.
  325. .sh FILES
  326. /etc/glob,
  327. which interprets `*', `?', and `['.
  328. .br
  329. /dev/null as a source of end-of-file.
  330. .sh "SEE ALSO"
  331. `The UNIX Time-Sharing System',
  332. CACM, July, 1974,
  333. which gives the theory of operation of the
  334. Shell.
  335. .br
  336. chdir (I), login (I), wait (I), shift (I)
  337. .sh BUGS
  338. There is no way to redirect the diagnostic output.
  339.