Commit Graph

143 Commits

Author SHA1 Message Date
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