home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / W2KPRK.iso / apps / posix / source / MAN / SH.PRT < prev    next >
Text File  |  1999-11-17  |  34KB  |  661 lines

  1. ash - a shell [ ] [ ] [ ] [ ] ...  Copyright 1989 by Kenneth Alm-
  2. quist.   is  a  version  of with features similar to those of the
  3. System V shell.  This manual page lists all the features  of  but
  4. concentrates on the ones not in other shells.
  5.  
  6. If the options is given, then the shell  executes  the  specified
  7. shell  command.   The  flag cause the shell to read commands from
  8. the standard input (after executing any  command  specified  with
  9. the option.  If neither the or options are set, then the first is
  10. taken as the name of a file to read commands from.   If  this  is
  11. impossible  because there are no arguments following the options,
  12. then will set the flag and will read commands from  the  standard
  13. input.  The shell sets the initial value of the positional param-
  14. eters from the remaining after any used as the name of a file  of
  15. commands  is deleted.  The flags (other than are set by preceding
  16. them with ``-'' and cleared by preceding them with ``+''; see the
  17. builtin  command  for  a list of flags.  If no value is specified
  18. for the flag, the flag is set, and the standard input and  output
  19. of  the  shell  are connected to terminals, then the flag will be
  20. set.  If no value is specified for the flag, then the  flag  will
  21. be  set  if  the flag is set.  When the shell is invoked with the
  22. option, it is good practice to include the flag  if  the  command
  23. was  entered interactively by a user.  For compatibility with the
  24. System V shell, the option should come after the option.  If  the
  25. first character of argument zero to the shell is ``-'', the shell
  26. is assumed to be a login shell, and the files  and  are  read  if
  27. they  exist.   If the environment variable SHINIT is set on entry
  28. to the shell, the commands in SHINIT are normally parsed and exe-
  29. cuted.   SHINIT is not examined if the shell is a login shell, or
  30. if it the shell is running a shell procedure.   (A shell is  con-
  31. sidered  to  be  running a shell procedure if neither the nor the
  32. options are set.)
  33.  
  34. A is a sequence of zero or more commands separated  by  newlines,
  35. semicolons,  or  ampersands,  and optionally terminated by one of
  36. these three characters.  (This differs from the System  V  shell,
  37. which  requires  a  list  to contain at least one command in most
  38. cases.)  The commands in a list are executed in  the  order  they
  39. are  written.   If command is followed by an ampersand, the shell
  40. starts the command and immediately proceed onto the next command;
  41. otherwise it waits for the command to terminate before proceeding
  42. to the next one.  ``&&'' and ``||'' are binary operators.  ``&&''
  43. executes  the first command, and then executes the second command
  44. iff the exit status of the first  command  is  zero.   ``||''  is
  45. similar,  but  executes the second command iff the exit status of
  46. the first command is nonzero.  ``&&'' and ``||''  both  have  the
  47. same  priority.   The  ``|''  operator is a binary operator which
  48. feeds the standard output of the first command into the  standard
  49. input of the second command.  The exit status of the ``|'' opera-
  50. tor is the exit status of the second command.  ``|'' has a higher
  51. priority than ``||'' or ``&&''.  An command looks like
  52.  
  53.     if list
  54.     then    list
  55.   [ elif list
  56.       then  list ] ...
  57.   [ else  list ]
  58.     fi
  59.  
  60. A command looks like
  61.  
  62.     while list
  63.     do      list
  64.     done
  65.  
  66. The two lists are executed repeatedly while the  exit  status  of
  67. the first list is zero.  The command is similar, but has the word
  68. in place of
  69.  repeats until the exit status of the first list  is  zero.   The
  70. command looks like
  71.  
  72.     for variable in word...
  73.     do      list
  74.     done
  75.  
  76. The words are expanded, and then the list is executed  repeatedly
  77. with  the variable set to each word in turn.  and may be replaced
  78. with ``{'' and ``}''.  The and commands look like
  79.  
  80.     break [ num ]
  81.     continue [ num ]
  82.  
  83. terminates the innermost  or  loops.   continues  with  the  next
  84. iteration  of the innermost loop.  These are implemented as buil-
  85. tin commands.  The command looks like
  86.  
  87.     case word in
  88.     pattern) list ;;
  89.     ...
  90.     esac
  91.  
  92. The pattern can actually be one or  more  patterns  (see  below),
  93. separated  by ``|'' characters.  Commands may be grouped by writ-
  94. ing either
  95.  
  96.     (list)
  97.  
  98. or
  99.  
  100.     { list; }
  101.  
  102. The first of these executes the commands in a subshell.  A  func-
  103. tion definition looks like
  104.  
  105.     name ( ) command
  106.  
  107. A function definition is an executable statement;  when  executed
  108. it  installs a function named and returns an exit status of zero.
  109. The command is normally a list enclosed between ``{'' and  ``}''.
  110. Variables  may  be  declared to be local to a function by using a
  111. command.  This should appear as the first staement of a function,
  112. and looks like
  113.  
  114.     local [ variable | - ] ...
  115.  
  116. is implemented as a builtin command.  When a variable is made lo-
  117. cal,  it  inherits  the  initial  value and exported and readonly
  118. flags from the variable with the same  name  in  the  surrounding
  119. scope, if there is one.  Otherwise, the variable is initially un-
  120. set.  uses dynamic scoping, so that if you make the variable  lo-
  121. cal to function which then calls function references to the vari-
  122. able made inside will refer to the variable declared  inside  not
  123. to  the global variable named The only special parameter than can
  124. be made local is ``-''.  Making ``-''  local  any  shell  options
  125. that  are  changed  via the command inside the function to be re-
  126. stored to their original values when the function  returns.   The
  127. command looks like
  128.  
  129.     return [ exitstatus ]
  130.  
  131. It terminates the currently executing function.   is  implemented
  132. as a builtin command.
  133.  
  134. A simple command is a sequence of words.  The execution of a sim-
  135. ple command proceeds as follows.  First, the leading words of the
  136. form ``name=value'' are stripped off and assigned to the environ-
  137. ment of the command.  Second, the words are expanded.  Third, the
  138. first remaining word is taken as the command name that command is
  139. located.   Fourth,  any  redirections  are performed.  Fifth, the
  140. command is executed.  We look at these operations in reverse ord-
  141. er.   The  execution  of the command varies with the type of com-
  142. mand.  There are three types of commands:  shell functions, buil-
  143. tin commands, and normal programs.  When a shell function is exe-
  144. cuted, all of the shell positional parameters (except  $0,  which
  145. remains  unchanged)  are set to the parameters to the shell func-
  146. tion.  The variables which are explicitly placed in the  environ-
  147. ment  of  the  command (by placing assignments to them before the
  148. function name) are made local to the  function  and  are  set  to
  149. values  given.  Then the command given in the function definition
  150. is executed.  The positional parameters  are  restored  to  their
  151. original  values  when the command completes.  Shell builtins are
  152. executed internally to the shell, without spawning a new process.
  153. When  a  normal  program is executed, the shell runs the program,
  154. passing the parameters and the environment to  the  program.   If
  155. the  program  is  a shell procedure, the shell will interpret the
  156. program in a subshell.  The shell  will  reinitialize  itself  in
  157. this  case, so that the effect will be as if a new shell had been
  158. invoked to handle the shell procedure, except that  the  location
  159. of commands located in the parent shell will be remembered by the
  160. child.  If the program is  a  file  beginning  with  ``#!'',  the
  161. remainder of the first line specifies an interpreter for the pro-
  162. gram.  The shell (or the operating system, under  Berkeley  UNIX)
  163. will  run the interpreter in this case.  The arguments to the in-
  164. terpreter will consist of any arguments given on the  first  line
  165. of  the program, followed by the name of the program, followed by
  166. the arguments passed to the program.
  167.  
  168. Input/output redirections can be intermixed with the words  in  a
  169. simple  command and can be placed following any of the other com-
  170. mands.  When redirection occurs, the shell saves the  old  values
  171. of  the  file descriptors and restores them when the command com-
  172. pletes.  The ``<'', ``>'', and ``>>'' redirections  open  a  file
  173. for  input, output, and appending, respectively.  The ``<&digit''
  174. and ``>&digit'' makes the input or output a duplicate of the file
  175. descriptor  numbered  by  the  digit.  If a minus sign is used in
  176. place of a digit, the  standard  input  or  standard  output  are
  177. closed.  The ``<< word'' redirection takes input from a document.
  178. As the shell encounters ``<<'' redirections,  it  collects  them.
  179. The  next  time  it encounters an unescaped newline, it reads the
  180. documents in turn.  The word following the ``<<''  specifies  the
  181. contents  of  the  line that terminates the document.  If none of
  182. the quoting methods ('', "", or \) are used to  enter  the  word,
  183. then  the  document  is treated like a word inside double quotes:
  184. ``$'' and backquote are expanded and backslash can be used to es-
  185. cape  these  and to continue long lines.  The word cannot contain
  186. any variable or command  substitutions,  and  its  length  (after
  187. quoting)  must be in the range of 1 to 79 characters.  If ``<<-''
  188. is used in place of ``<<'', then leading tabs  are  deleted  from
  189. the lines of the document.  (This is to allow you do indent shell
  190. procedures containing here documents in a natural  fashion.)  Any
  191. of  the preceding redirection operators may be preceded by a sin-
  192. gle digit specifying the file descriptor to be redirected.  There
  193. cannot  be  any white space between the digit and the redirection
  194. operator.
  195.  
  196. When locating a command, the shell first looks to see if it has a
  197. shell  function  by that name.  Then, if PATH does not contain an
  198. entry for "%builtin", it looks for  a  builtin  command  by  that
  199. name.   Finally,  it  searches each entry in PATH in turn for the
  200. command.  The value of the PATH variable should be  a  series  of
  201. entries  separated by colons.  Each entry consists of a directory
  202. name, or a directory name followed by a  flag  beginning  with  a
  203. percent  sign.   The  current directory should be indicated by an
  204. empty directory name.  If no percent sign is  present,  then  the
  205. entry causes the shell to search for the command in the specified
  206. directory.  If the flag is ``%builtin'' then the  list  of  shell
  207. builtin  commands is searched.  If the flag is ``%func'' then the
  208. directory is searched for a file which is read as  input  to  the
  209. shell.  This file should define a function whose name is the name
  210. of the command being searched for.  Command  names  containing  a
  211. slash  are  simply  executed  without performing any of the above
  212. searches.
  213.  
  214. The environment of a command is a set of name/value pairs.   When
  215. the  shell  is invoked, it reads these names and values, sets the
  216. shell variables with these names to the corresponding values, and
  217. marks the variables as exported.  The command can be used to mark
  218. additional variables as exported.  The environment of  a  command
  219. is  constructed by constructing name/value pairs from all the ex-
  220. ported shell variables, and then modifying this set  by  the  as-
  221. signments which precede the command, if any.
  222.  
  223. The process of evaluating words when a shell procedure is execut-
  224. ed  is called Expansion consists of four steps:  variable substi-
  225. tution, command substitution, word splitting, and file name  gen-
  226. eration.   If  a  word  is the expression following the word in a
  227. case statement, the file name which follows a redirection symbol,
  228. or  an  assignment to the environment of a command, then the word
  229. cannot be split into multiple words.  In these  cases,  the  last
  230. two steps of the expansion process are omitted.
  231.  
  232. To be written.
  233.  
  234. accepts two syntaxes for command substitution: `list`
  235.  
  236. and $(list)
  237.  
  238. Either of these may be included in a word.   During  the  command
  239. substitution  process,  the command (syntactly a will be executed
  240. and anything that the command writes to the standard output  will
  241. be captured by the shell.  The final newline (if any) of the out-
  242. put will be deleted; the rest of the output will  be  substituted
  243. for the command in the word.
  244.  
  245. When the value of a variable or the output of a command  is  sub-
  246. stituted, the resulting text is subject to word splitting, unless
  247. the dollar sign introducing the variable or backquotes containing
  248. the  text were enclosed in double quotes.  In addition, ``$@'' is
  249. subject to a special type of splitting, even in the  presence  of
  250. double quotes.  Ash uses two different splitting algorithms.  The
  251. normal approach, which is intended for splitting  text  separated
  252. by which space, is used if the first character of the shell vari-
  253. able IFS is a space.  Otherwise an alternative experimental algo-
  254. rithm,  which  is  useful  for  splitting (possibly empty) fields
  255. separated by a separator character,  is  used.   When  performing
  256. splitting,  the  shell  scans  the replacement text looking for a
  257. character (when IFS does not begin with a space) or a sequence of
  258. characters  (when IFS does begin with a space), deletes the char-
  259. acter or sequence of characters, and  spits  the  word  into  two
  260. strings  at  that point.  When IFS begins with a space, the shell
  261. deletes either of the strings if they are  null.   As  a  special
  262. case,  if  the  word  containing the replacement text is the null
  263. string, the word is deleted.  The variable ``$@'' is  special  in
  264. two  ways.   First,  splitting takes place between the positional
  265. parameters, even if  the  text  is  enclosed  in  double  quotes.
  266. Second,  if  the word containing the replacement text is the null
  267. string and there are no positional parameters, then the  word  is
  268. deleted.  The result of these rules is that "$@" is equivalent to
  269. "$1" "$2" ... "$n", where n is the number of  positional  parame-
  270. ters.  (Note that this differs from the System V shell.  The Sys-
  271. tem V documentation claims that "$@" behaves this way; in fact on
  272. the System V shell "$@" is equivalent to "" when there are no po-
  273. sitional paramteters.)
  274.  
  275. Unless the flag is set, file name generation is  performed  after
  276. word  splitting  is complete.  Each word is viewed as a series of
  277. patterns, separated by slashes.  The  process  of  expansion  re-
  278. places  the word with the names of all existing files whose names
  279. can be formed by  replacing  each  pattern  with  a  string  that
  280. matches  the  specified  pattern.   There are two restrictions on
  281. this:  first, a pattern cannot match a string containing a slash,
  282. and  second,  a  pattern  cannot  match  a string starting with a
  283. period unless the first character of the pattern is a period.  If
  284. a word fails to match any files and the flag is not set, then the
  285. word will be left unchanged (except that the meta-characters will
  286. be converted to normal characters).  If the flag is set, then the
  287. word is only left unchanged if none of  the  patterns  contain  a
  288. character  that can match anything besides itself.  Otherwise the
  289. flag forces the word to be replaced with the names of  the  files
  290. that it matches, even if there are zero names.
  291.  
  292. A consists of normal  characters,  which  match  themselves,  and
  293. meta-characters.   The  meta-characters  are ``!'', ``*'', ``?'',
  294. and ``[''.  These characters lose there special meanings if  they
  295. are  quoted.   When command or variable substitution is performed
  296. and the dollar sign or back quotes are  not  double  quoted,  the
  297. value of the variable or the output of the command is scanned for
  298. these characters and they are turned into  meta-characters.   Two
  299. exclamation  points  at  the beginning of a pattern function as a
  300. ``not'' operator, causing the pattern to match  any  string  that
  301. the  remainder  of  the  pattern does match.  Other occurances of
  302. exclamation points in a pattern match  exclamation  points.   Two
  303. exclamation  points  are required rather than one to decrease the
  304. incompatibility with the System V shell  (which  does  not  treat
  305. exclamation  points  specially).  An asterisk (``*'') matches any
  306. string of characters.  A question mark matches any single charac-
  307. ter.   A  left bracket (``['') introduces a character class.  The
  308. end of the character class is indicated by a ``]''; if the  ``]''
  309. is missing then the ``['' matches a ``['' rather than introducing
  310. a character class.  A character class matches any of the  charac-
  311. ters  between  the square brackets.  A range of characters may be
  312. specified using a minus sign.  The character class may be comple-
  313. mented  by making an exclamation point the first character of the
  314. character class.  To include a ``]'' in a character  class,  make
  315. it  the first character listed (after the ``!'', if any).  To in-
  316. clude a minus sign, make it the first or last character listed.
  317.  
  318. By convention, the name ``/u/user'' refers to the home  directory
  319. of  the  specified user.  There are good reasons why this feature
  320. should be supported by the file system (using a feature  such  as
  321. symbolic  links) rather than by the shell, but is capable of per-
  322. forming this mapping if the file system doesn't.  If the  mapping
  323. is done by setting the flag will turn it off.
  324.  
  325. silently discards nul characters.  Any other  character  will  be
  326. handled correctly by including characters with the high order bit
  327. set.
  328.  
  329. The term refers to a process created by a shell  command,  or  in
  330. the  case of a pipeline, to the set of processes in the pipeline.
  331. The ways to refer to a job are: %number %string %% process_id
  332.  
  333. The first form identifies a job by job number.  When a command is
  334. run,  assigns  it  a  job number (the lowest unused number is as-
  335. signed).  The second form identifies a job by giving a prefix  of
  336. the  command  used to create the job.  The prefix must be unique.
  337. If there is only one job, then the null prefix will identify  the
  338. job,  so  you  can  refer to the job by writing ``%''.  The third
  339. form refers to the current job.  The current job is the last  job
  340. to  be  stopped  while  it  was in the foreground.  (See the next
  341. paragraph.)  The last form identifies a job by giving the process
  342. id  of the last process in the job.  If the operating system that
  343. is running on supports job control, will allow you to use it.  In
  344. this case, typing the suspend character (typically ^Z) while run-
  345. ning a command will return you to and  will  make  the  suspended
  346. command  the  current  job.  You can then continue the job in the
  347. background by typing or you can continue it in the foreground  by
  348. typing
  349.  
  350. If the shell variable ATTY is set, and the shell variable TERM is
  351. not  set  to ``emacs'', then ash generates appropriate escape se-
  352. quences to talk to
  353.  
  354. By tradition, an exit status of zero means  that  a  command  has
  355. succeeded  and  a  nonzero exit status indicates that the command
  356. failed.  This is better than no convention at all, but  in  prac-
  357. tice it is extremely useful to allow commands that succeed to use
  358. the exit status to return information to the caller.   A  variety
  359. of  better  conventions  have been proposed, but none of them has
  360. met with universal approval.  The convention used by ash and  all
  361. the programs included in the ash distribution is as follows:
  362.           0         Success.
  363.           1         Alternate success.
  364.           2         Failure.
  365.           129-...   Command terminated by a signal.
  366. The alternate success return is  used  by  commands  to  indicate
  367. various  conditions  which  are  not errors but which can, with a
  368. little imagination, be conceived of as less successful than plain
  369. success.   For  example,  returns  1 when the tested condition is
  370. false and returns 1 when there are no more options.  Because this
  371. convention  is  not  used  universally,  the option of causes the
  372. shell to exit when a command returns 1 even though that  contrad-
  373. icts the convention described here.  When a command is terminated
  374. by a signal, the uses 128 plus the signal number as the exit code
  375. for the command.
  376.  
  377. This concluding section lists  the  builtin  commands  which  are
  378. builtin because they need to perform some operation that can't be
  379. performed by a separate process.  In addition to these, there are
  380. several  other commands and which can optionally be compiled into
  381. the shell.  The builtin commands described below that accept  op-
  382. tions use the System V Release 2 syntax.
  383.  
  384. [ ] ...
  385. Continue the specified jobs (or the current job if  no  jobs  are
  386. given) in the background.  This command is only available on sys-
  387. tems with Bekeley job control.
  388. Execute the specified builtin command.  (This is useful when  you
  389. have a shell function with the same name as a builtin command.) [
  390. ]
  391. Switch to the specified directory (default $HOME).  If the an en-
  392. try  for  CDPATH  appears in the environment of the cd command or
  393. the shell variable CDPATH is set and the directory name does  not
  394. begin with a slash, then the directories listed in CDPATH will be
  395. searched for the specified directory.  The format  of  CDPATH  is
  396. the  same  as that of PATH.  In an interactive shell, the cd com-
  397. mand will print out the name of the directory  that  it  actually
  398. switched  to  if  this  is  different from the name that the user
  399. gave.  These may be different either because the CDPATH mechanism
  400. was used or because a symbolic link was crossed.
  401. The commands in the specified file are read and executed  by  the
  402. shell.   A  path  search is not done to find the file because the
  403. directories in PATH generally contain files that are intended  to
  404. be executed, not read.
  405. The strings are parsed as shell  commands  and  executed.   (This
  406. differs from the System V shell, which concatenates the arguments
  407. (separated by spaces) and parses the result as a single command.)
  408. [ ]
  409. Unless is omitted, the shell process is replaced with the  speci-
  410. fied  program  (which must be a real program, not a shell builtin
  411. or function).  Any redirections on the exec command are marked as
  412. permanent, so that they are not undone when the exec command fin-
  413. ishes.  If the command is not found, the exec command causes  the
  414. shell to exit.  [ ]
  415. Terminate the shell process.  If is given it is used as the  exit
  416. status  of  the shell; otherwise the exit status of the preceding
  417. command is used.
  418. The specified names are exported so that they will appear in  the
  419. environment  of subsequent commands.  The only way to un-export a
  420. variable is to unset it.  allows the value of a  variable  to  be
  421. set at the same time it is exported by writing
  422.  
  423.     export name=value
  424.  
  425. With no arguments the export command lists the names of  all  ex-
  426. ported variables.  [ ]
  427. Move the specified job or the  current  job  to  the  foreground.
  428. This  command  is only available on systems with Bekeley job con-
  429. trol.
  430. The System V command.
  431. The shell maintains a hash table which remembers the locations of
  432. commands.   With no arguments whatsoever, the hash command prints
  433. out the contents of this table.   Entries  which  have  not  been
  434. looked  at since the last command are marked with an asterisk; it
  435. is possible for these entries to be invalid.
  436.  
  437. With arguments, the hash command removes the  specified  commands
  438. from  the hash table (unless they are functions) and then locates
  439. them.  With the option, prints the locations of the  commands  as
  440. it  finds  them.  The option causes the command to delete all the
  441. entries in the hash table except for functions.  [ ]
  442. Print the process id's of the processes in the job.  If  the  job
  443. argument is omitted, use the current job.
  444. This command lists out all the  background  processes  which  are
  445. children of the current shell process.  [ ]
  446. The function name is defined to execute the last command entered.
  447. If the function name is omitted, the last command executed is ex-
  448. ecuted again.  This command only works if the flag is set.
  449. Print the current directory.  The builtin command may differ from
  450. the  program  of  the  same  name  because  the  builtin  command
  451. remembers what the current directory is rather  than  recomputing
  452. it  each  time.   This  makes it faster.  However, if the current
  453. directory is renamed, the builtin version of pwd will continue to
  454. print the old name for the directory.  [ ] [ ]
  455. The prompt is printed if the option is specified and the standard
  456. input  is  a terminal.  Then a line is read from the standard in-
  457. put.  The trailing newline is deleted from the line and the  line
  458. is split as described in the section on word splitting above, and
  459. the pieces are assigned to the variables in order.  If there  are
  460. more  pieces than variables, the remaining pieces (along with the
  461. characters in IFS that separated them) are assigned to  the  last
  462. variable.  If there are more variables than pieces, the remaining
  463. variables are assigned the null string.
  464.  
  465. The option causes any backslashes in the input to be treated spe-
  466. cially.   If  a backslash is followed by a newline, the backslash
  467. and the newline will be deleted.  If a backslash is  followed  by
  468. any  other  character, the backslash will be deleted and the fol-
  469. lowing character will be treated as though it were  not  in  IFS,
  470. even if it is.
  471. The specified names are marked as read only, so that they  cannot
  472. be  subsequently  modified or unset.  allows the value of a vari-
  473. able to be set at the same time it is marked read only by writing
  474.  
  475.     readonly name=value
  476.  
  477. With no arguments the readonly command lists  the  names  of  all
  478. read only variables.  [ { | | } ]
  479. The command performs three different functions.
  480.  
  481. With no arguments, it lists the values of all shell variables.
  482.  
  483. If options are given, it sets  the  specified  option  flags,  or
  484. clears them if the option flags are introduced with a rather than
  485. a Only the first argument to can contain options.   The  possible
  486. options are:
  487.  
  488. -e  Causes the shell to exit when a  command  terminates  with  a
  489.     nonzero  exit status, except when the exit status of the com-
  490.     mand is explicitly tested.  The exit status of a  command  is
  491.     considered  to be explicitly tested if the command is used to
  492.     control an or or if the command is the left hand  operand  of
  493.     an ``&&'' or ``||'' operator.
  494.  
  495. -f  Turn off file name generation.
  496.  
  497. -I  Cause the shell to ignore  end  of  file  conditions.   (This
  498.     doesn't apply when the shell a script sourced using the ``.''
  499.     command.)  The shell will in fact exit if it gets 50 eof's in
  500.     a row.
  501.  
  502. -i  Make the shell interactive.  This causes the shell to  prompt
  503.     for  input,  to trap interrupts, to ignore quit and terminate
  504.     signals, and to return to the main command loop  rather  than
  505.     exiting on error.
  506.  
  507. -j  Turns on Berkeley job control, on systems  that  support  it.
  508.     When  the  shell starts up, the is set by default if the flag
  509.     is set.
  510.  
  511. -n  Causes the shell to  read  commands  but  not  execute  them.
  512.     (This  is  marginally  useful  for  checking  the  syntax  of
  513.     scripts.)
  514.  
  515. -s  If this flag is set when the shell starts up, the shell reads
  516.     commands  from its standard input.  The shell doesn't examine
  517.     the value of this flag any other time.
  518.  
  519. -x  If this flag is set, the shell will print  out  each  command
  520.     before executing it.
  521.  
  522. -z  If this flag is set, the file  name  generation  process  may
  523.     generate  zero files.  If it is not set, then a pattern which
  524.     does not match any files will be replaced by a quoted version
  525.     of the pattern.
  526.  
  527. The third use of the set command is to  set  the  values  of  the
  528. shell's  positional parameters to the specified To change the po-
  529. sitional parameters without changing any options, use  ``--''  as
  530. the  first  argument  to  If no args are present, the set command
  531. will leave the value of the positional parameters  unchanged,  so
  532. to  set  the  positional  parameters to set of values that may be
  533. empty, execute the command
  534.  
  535.     shift $#
  536.  
  537. first to clear out the old values of the positional parameters.
  538. Assigns to (In general it is better to write rather than using is
  539. intended  to be used in functions that assign values to variables
  540. whose names are passed as parameters.) [ ]
  541. Shift the positional parameters times.  A shift sets the value of
  542. $1 to the value of $2, the value of $2 to the value of $3, and so
  543. on, decreasing the value of $# by one.  If there are  zero  posi-
  544. tional parameters, shifting doesn't do anything.  [ ]
  545. Cause the shell to parse and execute when any  of  the  specified
  546. signals  are  received.   The  signals  are  specified  by signal
  547. number.  may be null or omitted; the former causes the  specified
  548. signal  to be ignored and the latter causes the default action to
  549. be taken.  When the shell forks off a subshell, it resets trapped
  550. (but  not  ignored) signals to the default action.  The trap com-
  551. mand has no effect on signals that were ignored on entry  to  the
  552. shell.  [ ]
  553. Set the value of umask (see to the specified octal value.  If the
  554. argument is omitted, the umask value is printed.
  555. The specified variables and functions are unset  and  unexported.
  556. If  a  given  name corresponds to both a variable and a function,
  557. both the variable and the function are unset.  [ ]
  558. Wait for the specified job to complete and return the exit status
  559. of the last process in the job.  If the argument is omitted, wait
  560. for all jobs to complete and the return an exit status  of  zero.
  561. The following function redefines the cd command:
  562.  
  563.     cd() {
  564.         if bltin cd "$@"
  565.         thenif test -f .enter
  566.         then. .enter
  567.         elsereturn 0
  568.         fi
  569.         fi
  570.     }
  571.  
  572. This function causes the file ``.enter''  to  be  read  when  you
  573. enter  a  directory,  if it exists.  The bltin command is used to
  574. access the real cd command.  The ``return 0''  ensures  that  the
  575. function  will  return  an exit status of zero if it successfully
  576. changes to a directory that does not contain a  ``.enter''  file.
  577. Redefining  existing commands is not always a good idea, but this
  578. example shows that you can do it if you  want  to.   The  suspend
  579. function distributed with looks like
  580.  
  581.     # Copyright (C) 1989 by Kenneth Almquist.  All rights reserved.
  582.     # This file is part of ash, which is distributed under the terms
  583.     # specified by the Ash General Public License.
  584.  
  585.     suspend() {
  586.         local -
  587.         set +j
  588.         kill -TSTP 0
  589.     }
  590.  
  591. This turns off job control and then sends a stop  signal  to  the
  592. current  process group, which suspends the shell.  (When job con-
  593. trol is turned on, the shell ignores the TSTP signal.)  Job  con-
  594. trol  will  be  turned  back on when the function returns because
  595. ``-'' is local to the function.  As an example of what not to do,
  596. consider an earlier version of suspend:
  597.  
  598.     suspend() {
  599.         suspend_flag=$-
  600.         set +j
  601.         kill -TSTP 0
  602.         set -$suspend_flag
  603.     }
  604.  
  605. There are two problems with this.  First, suspend_flag is a  glo-
  606. bal  variable  rather than a local one, which will cause problems
  607. in the (unlikely) circumstance that the user is using that  vari-
  608. able  for  some  other purpose.  Second, consider what happens if
  609. shell received an interrupt signal after it  executes  the  first
  610. set command but before it executes the second one.  The interrupt
  611. signal will abort the shell function, so that the second set com-
  612. mand  will  never  be  executed and job control will be left off.
  613. The first version of suspend avoids this problem by  turning  job
  614. control off only in a local copy of the shell options.  The local
  615. copy of the shell options is discarded when the function is  ter-
  616. minated,  no matter how it is terminated.  Shell variables can be
  617. used to provide abbreviations for things which you type frequent-
  618. ly.  For example, I set
  619.           export h=$HOME
  620. in my .profile so that I can type the name of my  home  directory
  621. simply  by typing ``$h''.  When writing shell procedures, try not
  622. to make assumptions about what is imported from the  environment.
  623. Explicitly  unset or initialize all variables, rather than assum-
  624. ing they will be unset.  If you use cd, it is a good idea to  un-
  625. set  CDPATH.   People sometimes use ``<&-'' or ``>&-'' to provide
  626. no input to a command or to discard the output of a  command.   A
  627. better  way  to do this is to redirect the input or output of the
  628. command to Word splitting and file name generation are  performed
  629. by  default,  and  you  have  to  explicitly use double quotes to
  630. suppress it.  This is backwards, but you can learn to  live  with
  631. it.   Just get in the habit of writing double quotes around vari-
  632. able and command substitutions, and omit them only when you real-
  633. ly  want  word  splitting  and file name generation.  If you want
  634. word splitting but not file  name  generation,  use  the  option.
  635. Kenneth  Almquist  echo(1),  expr(1),  line(1),  pwd(1), true(1).
  636. When command substitution occurs inside a here document, the com-
  637. mands  inside the here document are run with their standard input
  638. closed.  For example, the following will  not  word  because  the
  639. standard  input of the command will be closed when the command is
  640. run:
  641.  
  642.     cat <<-!
  643.     Line 1: $(line)
  644.     Line 2: $(line)
  645.     !
  646.  
  647. Unsetting a function which is currently being executed may  cause
  648. strange  behavior.  The shell syntax allows a here document to be
  649. terminated by an end of file as well as by a line containing  the
  650. terminator  word  which  follows  the ``<<''.  What this means is
  651. that if you mistype the terminator line, the shell will  silently
  652. swallow up the rest of your shell script and stick it in the here
  653. document.
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.