Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 1 | http://www.opengroup.org/onlinepubs/9699919799/ |
| 2 | Open Group Base Specifications Issue 7 |
Denis Vlasenko | e471275 | 2007-04-14 15:08:41 +0000 | [diff] [blame] | 3 | |
Denis Vlasenko | 12c0622 | 2008-02-14 08:52:30 +0000 | [diff] [blame] | 4 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 5 | http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html |
| 6 | Shell & Utilities |
Denis Vlasenko | cccdc4e | 2007-11-23 21:08:38 +0000 | [diff] [blame] | 7 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 8 | It says that any of the standard utilities may be implemented |
| 9 | as a regular shell built-in. It gives a list of utilities which |
| 10 | are usually implemented that way (and some of them can only |
| 11 | be implemented as built-ins, like "alias"): |
Denis Vlasenko | d67cef2 | 2007-06-13 06:47:47 +0000 | [diff] [blame] | 12 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 13 | alias |
| 14 | bg |
| 15 | cd |
| 16 | command |
| 17 | false |
| 18 | fc |
| 19 | fg |
| 20 | getopts |
| 21 | jobs |
| 22 | kill |
| 23 | newgrp |
| 24 | pwd |
| 25 | read |
| 26 | true |
| 27 | umask |
| 28 | unalias |
| 29 | wait |
Denis Vlasenko | d76c049 | 2007-05-25 02:16:25 +0000 | [diff] [blame] | 30 | |
Denis Vlasenko | 163a855 | 2007-05-24 13:52:46 +0000 | [diff] [blame] | 31 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 32 | http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html |
| 33 | Shell Command Language |
Denis Vlasenko | 8805eeb | 2007-05-21 10:19:48 +0000 | [diff] [blame] | 34 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 35 | It says that shell must implement special built-ins. Special built-ins |
| 36 | differ from regular ones by the fact that variable assignments |
Denys Vlasenko | 131ed3b | 2010-05-20 12:56:14 +0200 | [diff] [blame] | 37 | done on special builtin are *PRESERVED*. That is, |
Denis Vlasenko | 21f0d4c | 2007-05-06 14:15:42 +0000 | [diff] [blame] | 38 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 39 | VAR=VAL special_builtin; echo $VAR |
Denis Vlasenko | ac0e5ab | 2007-05-04 21:37:27 +0000 | [diff] [blame] | 40 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 41 | should print VAL. |
Denis Vlasenko | 400c5b6 | 2007-05-04 13:07:27 +0000 | [diff] [blame] | 42 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 43 | (Another distinction is that an error in special built-in should |
| 44 | abort the shell, but this is not such a critical difference, |
| 45 | and moreover, at least bash's "set" does not follow this rule, |
Denys Vlasenko | 131ed3b | 2010-05-20 12:56:14 +0200 | [diff] [blame] | 46 | which is even codified in autoconf configure logic now...) |
Denis Vlasenko | e725bfe | 2007-05-03 22:45:39 +0000 | [diff] [blame] | 47 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 48 | List of special builtins: |
Denis Vlasenko | 08c8c1d | 2007-04-28 22:39:02 +0000 | [diff] [blame] | 49 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 50 | . file |
| 51 | : [argument...] |
| 52 | break [n] |
| 53 | continue [n] |
| 54 | eval [argument...] |
| 55 | exec [command [argument...]] |
| 56 | exit [n] |
| 57 | export name[=word]... |
| 58 | export -p |
| 59 | readonly name[=word]... |
| 60 | readonly -p |
| 61 | return [n] |
| 62 | set [-abCefhmnuvx] [-o option] [argument...] |
| 63 | set [+abCefhmnuvx] [+o option] [argument...] |
| 64 | set -- [argument...] |
| 65 | set -o |
| 66 | set +o |
| 67 | shift [n] |
| 68 | times |
| 69 | trap n [condition...] |
| 70 | trap [action condition...] |
| 71 | unset [-fv] name... |
Denis Vlasenko | 1359da6 | 2007-04-21 23:27:30 +0000 | [diff] [blame] | 72 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 73 | In practice, no one uses this obscure feature - none of these builtins |
| 74 | gives any special reasons to play such dirty tricks. |
Denis Vlasenko | 52881e9 | 2007-04-21 13:42:52 +0000 | [diff] [blame] | 75 | |
Denys Vlasenko | 131ed3b | 2010-05-20 12:56:14 +0200 | [diff] [blame] | 76 | However. This section also says that *function invocation* should act |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 77 | similar to special built-in. That is, variable assignments |
| 78 | done on function invocation should be preserved after function invocation. |
Denis Vlasenko | 2f1bb36 | 2007-04-21 10:01:14 +0000 | [diff] [blame] | 79 | |
Denys Vlasenko | 0e81e48 | 2010-05-17 23:51:00 +0200 | [diff] [blame] | 80 | This is significant: it is not unthinkable to want to run a function |
| 81 | with some variables set to special values. But because of the above, |
| 82 | it does not work: variable will "leak" out of the function. |