Commit Graph

208 Commits

Author SHA1 Message Date
Jilles Tjoelker
ea381e691a sh(1): Reduce excessive semicolon-separated sentences.
Reported by:	Benjamin Kaduk
2011-03-06 21:20:53 +00:00
Jilles Tjoelker
075b72ef01 sh(1): Update description of arithmetic. 2011-02-08 23:19:40 +00:00
Jilles Tjoelker
604e8224f8 sh: Do not try to execute binary files as scripts.
If execve() returns an [ENOEXEC] error, check if the file is binary before
trying to execute it using sh. A file is considered binary if at least one
of the first 256 bytes is '\0'.

In particular, trying to execute ELF binaries for the wrong architecture now
fails with an "Exec format error" message instead of syntax errors and
potentially strange results.
2011-02-05 12:54:59 +00:00
Jilles Tjoelker
3835f47c7e sh: Remove special code for shell scripts without magic number.
These are called "shell procedures" in the source.

If execve() failed with [ENOEXEC], the shell would reinitialize itself
and execute the program as a script. This requires a fair amount of code
which is not frequently used (most scripts have a #! magic number).
Therefore just execute a new instance of sh (_PATH_BSHELL) to run the
script.
2011-02-04 22:47:55 +00:00
Jilles Tjoelker
421fb02139 sh(1): Document changes to 'exit' from traps. 2011-01-16 14:11:50 +00:00
Jilles Tjoelker
12dfb7a554 sh(1): Explain why it is a bad idea to use aliases in scripts. 2010-12-21 22:48:56 +00:00
Jilles Tjoelker
0a62a9caa9 sh: Add kill builtin.
This allows specifying a %job (which is equivalent to the corresponding
process group).

Additionally, it improves reliability of kill from sh in high-load
situations and ensures "kill" finds the correct utility regardless of PATH,
as required by POSIX (unless the undocumented %builtin mechanism is used).

Side effect: fatal errors (any error other than kill(2) failure) now return
exit status 2 instead of 1. (This is consistent with other sh builtins, but
not in NetBSD.)

Code size increases about 1K on i386.

Obtained from:	NetBSD
2010-12-21 22:47:34 +00:00
Jilles Tjoelker
25f6b31fac sh(1): Clean up documentation of built-in commands.
Make sure all built-in commands are in the subsection named such, except
exp, let and wordexp which are deliberately undocumented. The text said only
built-ins that really need to be a built-in were documented there but in
fact almost all of them were already documented.
2010-12-03 23:24:27 +00:00
Jilles Tjoelker
b97d13b399 sh(1): Document that command's -p option also works with -v/-V.
This was implemented in r201343.
2010-12-01 23:26:32 +00:00
Jilles Tjoelker
9897c45f31 sh: Add printf builtin.
This was removed in 2001 but I think it is appropriate to add it back:
* I do not want to encourage people to write fragile and non-portable echo
  commands by making printf much slower than echo.
* Recent versions of Autoconf use it a lot.
* Almost no software still wants to support systems that do not have
  printf(1) at all.
* In many other shells printf is already a builtin.

Side effect: printf is now always the builtin version (which behaves
identically to /usr/bin/printf) and cannot be overridden via PATH (except
via the undocumented %builtin mechanism).

Code size increases about 5K on i386. Embedded folks might want to replace
/usr/bin/printf with a hard link to /usr/bin/alias.
2010-11-19 12:56:13 +00:00
Jilles Tjoelker
4b985a89e7 sh(1): Document r214304 (special builtin is illegal function name). 2010-11-12 22:40:18 +00:00
Jilles Tjoelker
f35d74beed sh(1): Update for r214492. "${v+"hi}there"}".
The part hi}there is not a quoted string but nevertheless the closing brace
does not terminate the expansion.
2010-11-12 22:28:47 +00:00
Jilles Tjoelker
3fdfd0a435 sh(1): Modernize the introduction a bit.
In particular, remove the text about ksh-like features, which are usually
taken for granted nowadays. The original Bourne shell is fading away and for
most users our /bin/sh is one of the most minimalistic they know.
2010-11-12 14:40:20 +00:00
Jilles Tjoelker
57a40f7d08 sh(1): Correct synopsis and make precise how $0 is set.
In particular, the extra argument to set $0 with -c was not documented.

MFC after:	1 week
2010-10-31 23:03:11 +00:00
Jilles Tjoelker
f1ec058177 sh(1): Clarify subshells/processes for pipelines.
For multi-command pipelines,
1. all commands are direct children of the shell (unlike the original
   Bourne shell)
2. all commands are executed in a subshell (unlike the real Korn shell)

MFC after:	1 week
2010-10-16 14:37:56 +00:00
Jilles Tjoelker
1217a4ead5 sh(1): Remove xrefs for expr(1) and getopt(1).
expr(1) should usually not be used as various forms of parameter expansion
and arithmetic expansion replicate most of its functionality in an easier
way.

getopt(1) should not be used at all in new code. Instead, getopts(1) or
entirely manual parsing should be used.

MFC after:	1 week
2010-09-10 13:40:31 +00:00
Jilles Tjoelker
36cf3efe41 sh(1): Add a brief summary of arithmetic expressions. 2010-08-22 13:04:00 +00:00
Jilles Tjoelker
ed4c3b5f86 sh: Forget about terminated background processes sooner.
Unless $! has been referenced for a particular job or $! still contains that
job's pid, forget about it after it has terminated. If $! has been
referenced, remember the job until the wait builtin has reported its
completion (either with the pid as parameter or without parameters).

In interactive mode, jobs are forgotten after termination has been reported,
which happens before primary prompts and through the jobs builtin. Even
then, though, remember a job if $! has been referenced.

This is similar to what is suggested by POSIX and should fix most memory
leaks (which also tend to cause sh to use more CPU time) with long running
scripts that start background jobs.

Caveats:
* Repeatedly referencing $! without ever doing 'wait', like
    while :; do foo & echo started foo: $!; sleep 60; done
  will still use a lot of memory and CPU time in the long run.
* The jobs and jobid builtins do not cause a job to be remembered for longer
  like expanding $! does.

PR:		bin/55346
2010-06-29 22:37:45 +00:00
Jilles Tjoelker
1788b7ffb9 sh(1): Rework documentation of shell variables.
* Move the "environment variables" that do not need exporting to be
  effective or that are set by the shell without exporting to a new section
  "Special Variables".
* Add special variables LINENO and PPID.
* Add environment variables LANG, LC_* and PWD; also describe ENV under
  environment variables.
2010-05-24 15:12:12 +00:00
Jilles Tjoelker
626a7b1d90 sh(1): Improve wording of 'Special Parameters' section. 2010-05-24 13:28:12 +00:00
Jilles Tjoelker
d806a030d5 sh(1): Fix "reserved word" vs "keyword" inconsistency.
Use "keyword" everywhere, like the output of the 'type' builtin, and only
mention "reserved word" once to say it is the same thing.
2010-05-09 22:03:18 +00:00
Jilles Tjoelker
d5f6b530fc sh: Automatically enable -o emacs in interactive shells with terminals.
This makes sh a bit more friendly in single user mode, make buildenv, chroot
and the like, and matches other shells.

The -o emacs can be overridden on the command line or in the ENV file.
2010-04-05 14:15:51 +00:00
Jilles Tjoelker
227c8e2a66 sh: Document the expansion changes in the man page.
Note that the following sentence
> Enclosing the full parameter expansion string in double-quotes does not
> cause the following four varieties of pattern characters to be quoted,
> whereas quoting characters within the braces has this effect.
is now true, but used to be incorrect.
2010-04-04 13:17:05 +00:00
Jilles Tjoelker
c848bc18e8 sh: Improve the command builtin:
* avoid unnecessary fork
* allow executing builtins via command
* executing a special builtin via command removes its special properties

Obtained from:	NetBSD (parts)
2010-03-06 16:57:53 +00:00
Jilles Tjoelker
c8054a6197 sh(1): document ulimit -w (swapuse rlimit).
MFC after:	1 week
2009-12-31 22:33:58 +00:00
Jilles Tjoelker
776e6b3332 sh(1): Correct two places where "$@" lacked necessary quotes.
MFC after:	1 week
2009-12-31 22:01:17 +00:00
Jilles Tjoelker
64254a667a sh: Exempt $@ and $* from set -u
This seems more useful and will likely be in the next POSIX standard.

Also document more precisely in the man page what set -u does (note that
$@, $* and $! are the only special parameters that can ever be unset, all
the others are always set, although they may be empty).
2009-10-24 21:20:04 +00:00
Jilles Tjoelker
b139165ca6 Clarify quoting of word in ${v=word} in sh(1). 2009-10-07 22:21:53 +00:00
Jilles Tjoelker
9764aa4157 Mention that NUL characters are not allowed in sh(1) input.
I do not consider this a bug because POSIX permits it and argument strings
and environment variables cannot contain '\0' anyway.

PR:		bin/25542
MFC after:	2 weeks
2009-09-20 21:42:38 +00:00
Jilles Tjoelker
30268dfa3f Designate special builtins as such in command -V and type.
Also document various properties of special builtins that we implement.

Approved by:	ed (mentor) (implicit)
2009-06-24 22:04:04 +00:00
Jilles Tjoelker
a68fbc44ee Mention the range for the exit status for the exit special builtin.
The exit status may exceed 255 in some cases (return); even though it seems
unwise to rely on this, it is also unwise to assume that $? is always
between 0 and 255.

This resolves bin/124748 by documenting that 'exit -1' is not valid.

PR:		bin/124748
Approved by:	ed (mentor)
2009-06-07 15:04:43 +00:00
Jilles Tjoelker
fe40d6d3b1 sh: Make read's timeout (-t) apply to the entire line, not only the first
character.

This avoids using non-standard behaviour of the old (upto FreeBSD 7) TTY
layer: it reprocesses the input queue when switching to canonical mode. The
new TTY layer does not provide this functionality and so read -t worked
very poorly (first character is not echoed, cannot be backspaced but is
still read).

This also agrees with what most other shells with read -t do.

PR:		bin/129566
Reviewed by:	stefanf
Approved by:	ed (mentor)
2009-05-31 19:37:06 +00:00
Ed Schouten
331773cd07 Document the ulimit -p option in the sh(1) manual page.
When I imported the MPSAFE TTY code, I added the -p flag to sh(1)'s
ulimit, but I forgot to document it in the appropriate manual page.

Requested by:	stefanf
2008-08-30 22:35:21 +00:00
Ruslan Ermilov
dfe302ab34 Revise the markup. 2007-12-05 12:29:26 +00:00
Stefan Farfeleder
aafd6a87a6 The exit status of a case statement where none of the patterns is matched
is supposed to be 0, not the status of the previous command.

Reported by:	Eygene Ryabinkin
PR:		116559
Approved by:	re (gnn)
2007-10-04 16:14:48 +00:00
Stefan Farfeleder
de37e41c23 Add the POSIX option -p to the jobs builtin command. It prints the PID of the
process leader for each job.  Now the last specified option for the output
format (-l, -p or -s) wins, previously -s trumped -l.

PR:		99926
Submitted by:	Ed Schouten and novel (patches modified by me)
2006-10-07 16:51:16 +00:00
Ruslan Ermilov
9badf57f01 Markup fixes. 2006-09-17 17:40:07 +00:00
Yaroslav Tykhiy
9cdd1e3fea Tell more of the sh(1) history.
Acknowledge Kenneth Almquist's contribution in AUTHORS.

MFC after:	5 days
2006-07-29 09:56:29 +00:00
Yaroslav Tykhiy
108459221f Make it easier to find that we have test(1) built-in in sh(1).
MFC after:	3 days
2006-07-26 06:48:18 +00:00
Yaroslav Tykhiy
a6557dcb04 Document the fact that 'true' and 'false' are among sh(1) built-in commands.
MFC after:	3 days
2006-06-21 12:01:52 +00:00
Stefan Farfeleder
120c8e6c34 Implement the PS4 variable which is defined by the POSIX User Portability
Utilities option.  Its value is printed at the beginning of the line if tracing
(-x) is active.  PS4 defaults to the string "+ " which is compatible with the
old behaviour to always print "+ ".

We still need to expand variables in PS1, PS2 and PS4.

PR:		46441 (part of)
Submitted by:	schweikh
Obtained from:	NetBSD
2006-06-15 07:00:49 +00:00
Stefan Farfeleder
7d1a55fc97 Document that '#' starts a comment.
PR:		85103
Submitted by:	garys
Obtained from:	pdksh manual
Patch from:	Daniel Gerzo (with changes by me)
2006-01-01 16:02:12 +00:00
Stefan Farfeleder
0673e800e9 - Document trap's -l option and the behaviour of a missing action or a single
dash.
- Discourage the omission of the action.

PR:		70985 [1]
Submitted by:	Martin Kammerhofer
2005-12-08 21:18:59 +00:00
Stefan Farfeleder
7331342177 Clarify that the echo builtin takes an arbitrary number of strings.
Mention that spaces are printed between the strings.
2005-12-08 17:59:54 +00:00
Stefan Farfeleder
1974986a82 Add the times builtin. It reports the user and system time for the shell
itself and its children.  Instead of calling times() (as implied by POSIX) this
implementation directly calls getrusage() to get the times because this is more
convenient.
2005-12-04 18:44:21 +00:00
Ruslan Ermilov
8af1113166 -mdoc sweep. 2005-11-17 12:15:23 +00:00
Jesus R. Camou
d2f90294d4 Add local' and return' to the list of built-ins.
Submitted by:	garys
Approved by:	trhodes (mentor)
2005-11-03 00:15:19 +00:00
Stefan Farfeleder
33b222b992 Document command -v and -V.
Glanced at by:	simon
2005-10-29 13:08:35 +00:00
Stefan Farfeleder
1b16155934 Document that read -t timeout returns 1 if the timeout elapses. 2005-10-29 08:22:09 +00:00
Stefan Farfeleder
7405365947 Elaborate on the behaviour of set -e. 2005-09-10 09:28:39 +00:00
Stefan Farfeleder
ef9791a3cc Split the export synopsis into two lines as -p cannot be mixed with variable
names.
2005-09-09 21:06:03 +00:00
Ralf S. Engelschall
7b14d37fb1 fix typo: ommitted -> omitted 2005-09-06 16:08:37 +00:00
Stefan Farfeleder
a01459df60 Document that `in word ...' is optional in the for command. 2005-09-03 16:06:04 +00:00
Stefan Farfeleder
de4ad3826b Document that unalias can be used to remove several alias names. 2005-09-02 21:15:56 +00:00
Jesus R. Camou
19162ab914 Wrap a line due to a new sentence.
Noticed by:	simon
Approved by:	trhodes (mentor)
2005-08-29 21:28:12 +00:00
Jesus R. Camou
a886288efd o Discuss the ways to escape an alias.
o Fix the alias syntax lines.
o Refer to the Aliases subsection.

PR:		docs/84914
Submitted by:	garys
Approved by:	trhodes (mentor)
MFC after:	3 days
2005-08-29 06:47:43 +00:00
Stefan Farfeleder
faa1ed35ac Document umask's -S option. 2005-08-17 19:44:15 +00:00
Ruslan Ermilov
fb039b55dc Sorted sections and fixed prompt (PS[12]) strings.
Approved by:	re (blanket)
2005-06-14 08:25:00 +00:00
Ruslan Ermilov
fd50df303c Put the description of the -c option in the right place, as
promised by the Argument List Processing section introduction.
What follows the option in the options list is its long name,
not its argument (as is the case for the -c option).  Also
sort references in the SEE ALSO section.

Approved by:	re (blanket)
2005-06-14 07:50:44 +00:00
Giorgos Keramidas
38afdcbc3c Various sh(1) enhancements:
- Move the description of the ``-c string'' option closer to the option itself.
- Add an ENVIRONMENT section (1)
- Add more .Xr cross references to the SEE ALSO section.

Obtained from:  NetBSD (1)
2005-04-15 14:53:29 +00:00
Giorgos Keramidas
a762afe578 Use `.Pq Ql'' to quote single characters, instead of `.Pq Li''.
This makes the resulting output more aesthetically pleasing in
text-only terminals:

Reviewed by:	ru
2005-03-04 13:16:50 +00:00
Giorgos Keramidas
91ee1c5df6 Add a section describing the exit status of the shell.
Obtained from:	NetBSD
2005-03-04 12:40:07 +00:00
Warner Losh
9ddb49cbe4 /*- or .\"- or #- to begin license clauses. 2005-01-10 08:39:26 +00:00
Ruslan Ermilov
6fa13ec06f Scheduled mdoc(7) sweep. 2005-01-09 19:54:23 +00:00
Ceri Davies
6b4bbd8a2c Correct typo. 2005-01-04 12:44:25 +00:00
Maxim Konovalov
af5eb6fcc5 o Add a missed "." .
Reviewed by:	ru
MFC after:	3 weeks
2004-12-02 13:13:27 +00:00
Alfred Perlstein
43d6677ba1 When listing the special $ variables, ($!, $#, etc) list them as $!
instead of just !, this allows one to more easily locate/understand
the section of the manpage in question.

Additional wording correction by: keramida
Reviewed by: keramida
2004-11-01 19:05:04 +00:00
Tim J. Robbins
128dc4a2e3 Document missing multibyte character handling in utilities specified
by POSIX.
2004-07-03 02:03:44 +00:00
Ruslan Ermilov
eccea571a7 Mechanically kill hard sentence breaks. 2004-07-02 21:04:19 +00:00
Brian Feldman
4ad8968a7f Document the "return" built-in better: it will exit . (sources) and
the top-level shell instance, too.
2004-04-14 15:58:50 +00:00
Mark Murray
6195fb4102 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
Ruslan Ermilov
fe08efe680 mdoc(7): Use the new feature of the .In macro. 2003-09-08 19:57:22 +00:00
Ruslan Ermilov
d74e011ff0 mdoc(7) police: A better version of the same.
Approved by:	re (blanket)
2003-05-16 21:19:32 +00:00
Jens Schweikhardt
fbc8f8a2dc Fix references to non-existing or obsoleted man pages.
PR:	docs/51480 (only a small part)
Submitted by:	Diomidis D. Spinellis <dds@aueb.gr>
2003-04-30 19:18:50 +00:00
Tim J. Robbins
e9fa8fddd6 Document the -L and -P options to the cd and pwd commands as being
mutually exclusive. The fact that the most recent one specified on the
command line is the one that takes effect is an implementation detail and
users should not rely on this.
2003-04-12 03:20:28 +00:00
Tony Finch
1413f7de53 Improve the layout of the description of the various parameter expansion
modifiers. The paragraph that explains the difference between ${foo:-bar}
and ${foo-bar} etc. was not very visible.
2003-02-03 23:03:05 +00:00
Ruslan Ermilov
facc67676f mdoc(7) police: Deal with self-xrefs. 2002-12-24 13:41:48 +00:00
Ruslan Ermilov
f5d1157fd1 mdoc(7) police: markup nit. 2002-12-23 15:21:38 +00:00
Tom Rhodes
304199ce19 The code uses trapsasync, however the manual page uses asynctraps. Fix the
manual page to reflect the code.

PR:		45820
Submitted by:	Marco Molteni <molter@tin.it>
Discussed with:	tjr
2002-12-17 20:27:48 +00:00
Tony Finch
162ae3ae7f Document trap EXIT and trap SIGNAME. 2002-12-17 17:31:44 +00:00
Tim J. Robbins
df9e587beb There is a built-in command called "builtin"; spell its name correctly
after rev. 1.77 called it "built-in".
2002-08-24 12:41:23 +00:00
Tom Rhodes
7d971bbf29 s/filesystem/file system/ as discussed on -developers 2002-08-21 17:32:44 +00:00
Jens Schweikhardt
8eed22b1a6 Fix a few typos, among them s/builtin/built-in/ (except for the ref
to the builtin(1) man page.) This is for consistency with the spelling
both proposed by ispell as well as IEEE Std 1003.1-2001.

MFC after:	3 days
2002-08-21 15:05:55 +00:00
Ruslan Ermilov
9ba31ca074 mdoc(7) police: tidying. 2002-08-09 10:59:20 +00:00
Tim J. Robbins
7e1975c2b2 Add a -P/-o physical option which behaves similarly to bash/ksh's options
by the same name. This option makes the cd and pwd builtins behave physically
(as opposed to logically) by default.

Submitted by:	fanf
2002-07-25 10:57:39 +00:00
Tim J. Robbins
088acf9001 Add a `bind' builtin command, which is simply a wrapper around libedit's
builtin command of the same name. This allows the key bindings for the
shell's line editor to be changed.

MFC after:	2 weeks
2002-07-23 11:50:53 +00:00
Tim J. Robbins
2babaf74b5 Implement the P1003.2 `command' builtin command, which is used to suppress
shell function and alias lookup. The -p option has been implemented, the
UPE -v and -V options have not. The old `command' command has been renamed
to `builtin'.
2002-07-21 06:49:14 +00:00
Tim J. Robbins
558175ca15 Document that only one of the -n and -e options may be specified for
sh(1)'s echo(1) builtin command.

PR:		32935, 40747
MFC after:	1 week
2002-07-20 04:39:23 +00:00
Matthew Dillon
2d41ef4b59 Fix type-o in last commit in preparation for MFC. 2002-07-02 19:06:33 +00:00
Sheldon Hearn
62df9b6286 Document addition of RLIMIT_VMEM support, added in rev 1.26 of miscbltin.c. 2002-06-27 16:56:45 +00:00
Tim J. Robbins
029c8ee4fa Bring documentation on CDPATH and its effects on cd(1) back into sync with
reality (and POSIX): current directory isn't searched unless CDPATH has
a "." element or is unset.

PR:		38442
Submitted by:	oleg dashevskii <be9@be9.ru>
MFC after:	1 week
2002-06-19 12:04:22 +00:00
Tim J. Robbins
8b34ad92a2 Document the -f and -v options of the unset builtin. 2002-06-06 04:12:50 +00:00
Tim J. Robbins
45086f8cf6 Add the SUSv3 -p ("portable") option to both the export and readonly
builtins. This makes export/readonly print lines in the form
"export name=value".
2002-06-06 03:57:22 +00:00
Tim J. Robbins
e5341cbb17 Quote alias values in the output of the alias(1) builtin so they are
suitable for re-input to the shell (SUSv3)
2002-06-04 12:59:12 +00:00
Tim J. Robbins
ad8a075902 Add -s (output PID's only) and -l (show PID's) options to the jobs(1)
builtin. Modify the output format to match what SUSv3 requires.
2002-05-31 14:04:23 +00:00
Ruslan Ermilov
81e9cda2c9 mdoc(7) police: tidy up the markup a bit. 2002-05-29 15:38:59 +00:00
Tim J. Robbins
fc482908be sh appeared in Version 1, not System V.1. 2002-05-25 12:18:27 +00:00
Tim J. Robbins
d513af6a66 Implement `set +o', which displays the currently set options in a format
suitable for re-input into the shell.
2002-05-25 12:11:58 +00:00
Tim J. Robbins
178897f127 Add the SUSv3 -L and -P options to the cd and pwd builtin utilities. `Logical'
handling of .. is now the default.
2002-05-20 07:54:39 +00:00
Tim J. Robbins
1b5a48ff88 Implement the -u (-o nounset) option, which gives an error message if
an unset variable is expanded.

Obtained from:	NetBSD (bjh21, christos)
2002-05-19 08:30:16 +00:00