summaryrefslogtreecommitdiffstats
path: root/bin/sh/sh.1
Commit message (Collapse)AuthorAgeFilesLines
* Minor mdoc nits.joel2012-05-131-2/+2
|
* mdoc: fix column names, indentation, column separation within each row, andjoel2012-04-071-1/+1
| | | | | | | quotation. Also make sure we have the same amount of columns in each row as the number of columns we specify in the head arguments. Reviewed by: brueffer
* Remove trailing whitespace per mdoc lint warningeadler2012-03-291-1/+1
| | | | | | | Disussed with: gavin No objection from: doc Approved by: joel MFC after: 3 days
* Remove superfluous paragraph macro.joel2012-03-251-1/+0
|
* sh(1): Improve documentation of field splitting.jilles2011-11-051-11/+55
|
* sh(1): Extend documentation about subshells.jilles2011-07-101-8/+46
| | | | | | | | | | | Because sh executes commands in subshell environments without forking in more and more cases (particularly from 8.0 on), it makes sense to describe subshell environments more precisely using ideas from POSIX, together with some FreeBSD-specific items. In particular, the hash and times builtins may not behave as if their state is copied for a subshell environment while leaving the parent shell environment unchanged.
* sh(1): Improve documentation of shell patterns:jilles2011-06-241-5/+10
| | | | | | | | | | | * Shell patterns are also for ${var#pat} and the like. * An '!' by itself will not trigger pathname generation so do not call it a meta-character, even though it has a special meaning directly after an '['. * Character ranges are locale-dependent. * A '^' will complement a character class like '!' but is non-standard. MFC after: 1 week
* sh(1): Document the case command better.jilles2011-06-241-2/+13
| | | | | Suggested by: netchild Reviewed by: gjb
* sh: Add do-nothing -h option.jilles2011-06-181-1/+5
| | | | | | | | | | POSIX requires a -h option to sh and set, to locate and remember utilities invoked by functions as they are defined. Given that this locate-and-remember process is optional elsewhere, it seems safe enough to make this option do nothing. POSIX does not specify a long name for this option. Follow ksh in calling it "trackall".
* sh: Add case statement fallthrough (with ';&' instead of ';;').jilles2011-06-171-2/+7
| | | | | | | | | | | | Replacing ;; with the new control operator ;& will cause the next list to be executed as well without checking its pattern, continuing until a list ends with ;; or until the end of the case statement. This is like omitting "break" in a C "switch" statement. The sequence ;& was formerly invalid. This feature is proposed for the next POSIX issue in Austin Group issue #449.
* sh: Add support for named character classes in bracket expressions.jilles2011-06-151-1/+11
| | | | | Example: case x in [[:alpha:]]) echo yes ;; esac
* sh: Save/restore changed variables in optimized command substitution.jilles2011-06-121-5/+2
| | | | | | | | | | | In optimized command substitution, save and restore any variables changed by expansions (${var=value} and $((var=assigned))), instead of trying to determine if an expansion may cause such changes. If $! is referenced in optimized command substitution, do not cause jobs to be remembered longer. This fixes $(jobs $!) again, simplifies the man page and shortens the code.
* sh: Do parameter expansion on ENV before using it.jilles2011-06-101-3/+3
| | | | | | This is required by POSIX, and allows things like ENV=\$HOME/.shrc. Note that tilde expansion is explicitly not performed.
* sh: Do parameter expansion before printing PS4 (set -x).jilles2011-06-091-2/+2
| | | | | | | | | | | | | | | | The function name expandstr() and the general idea of doing this kind of expansion by treating the text as a here document without end marker is from dash. All variants of parameter expansion and arithmetic expansion also work (the latter is not required by POSIX but it does not take extra code and many other shells also allow it). Command substitution is prevented because I think it causes too much code to be re-entered (for example creating an unbounded recursion of trace lines). Unfortunately, our LINENO is somewhat crude, otherwise PS4='$LINENO+ ' would be quite useful.
* sh: Expand aliases after assignments and redirections.jilles2011-05-211-3/+3
|
* sh: Implement the cd -e flag proposed for the next POSIX issue.jilles2011-05-201-2/+11
| | | | | | | | | This reflects failure to determine the pathname of the new directory in the exit status (1). Normally, cd returns successfully if it did chdir() and the call was successful. In POSIX, -e only has meaning with -P; because our -L is not entirely compliant and may fall back to -P mode, -e has some effect with -L as well.
* sh: Add \u/\U support (in $'...') for UTF-8.jilles2011-05-081-2/+2
| | | | | | | | | | Because we have no iconv in base, support for other charsets is not possible. Note that \u/\U are processed using the locale that was active when the shell started. This is necessary to avoid behaviour that depends on the parse/execute split (for example when placing braces around an entire script). Therefore, UTF-8 encoding is implemented manually.
* sh(1): Update BUGS section for UTF-8 support.jilles2011-05-081-2/+7
|
* sh: Add $'quoting' (C-style escape sequences).jilles2011-05-051-2/+71
| | | | | | | | | | | | | | | | | | | | | | | | A string between $' and ' may contain backslash escape sequences similar to the ones in a C string constant (except that a single-quote must be escaped and a double-quote need not be). Details are in the sh(1) man page. This construct is useful to include unprintable characters, tabs and newlines in strings; while this can be done with a command substitution containing a printf command, that needs ugly workarounds if the result is to end with a newline as command substitution removes all trailing newlines. The construct may also be useful in future to describe unprintable characters without needing to write those characters themselves in 'set -x', 'export -p' and the like. The implementation attempts to comply to the proposal for the next issue of the POSIX specification. Because this construct is not in POSIX.1-2008, using it in scripts intended to be portable is unwise. Matching the minimal locale support in the rest of sh, the \u and \U sequences are currently not useful. Exp-run done by: pav (with some other sh(1) changes)
* sh(1): Describe subshell environment, command substitution more correctly.jilles2011-03-201-7/+19
| | | | | | | | | | | POSIX does not require the shell to fork for a subshell environment, and we use that possibility in various ways (command substitutions with a single command and most subshells that are the final command of a shell process). Therefore do not tie subshells to forking in the man page. Command substitutions with expansions are a bit strange, causing a fork for $(...$(($x))...) because $x might expand to y=2; they will probably be changed later but this is how they work now.
* sh(1): Reduce excessive semicolon-separated sentences.jilles2011-03-061-4/+4
| | | | Reported by: Benjamin Kaduk
* sh(1): Update description of arithmetic.jilles2011-02-081-8/+3
|
* sh: Do not try to execute binary files as scripts.jilles2011-02-051-0/+1
| | | | | | | | | | 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.
* sh: Remove special code for shell scripts without magic number.jilles2011-02-041-10/+4
| | | | | | | | | | 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.
* sh(1): Document changes to 'exit' from traps.jilles2011-01-161-2/+7
|
* sh(1): Explain why it is a bad idea to use aliases in scripts.jilles2010-12-211-3/+4
|
* sh: Add kill builtin.jilles2010-12-211-1/+6
| | | | | | | | | | | | | | | | | 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
* sh(1): Clean up documentation of built-in commands.jilles2010-12-031-11/+14
| | | | | | | 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.
* sh(1): Document that command's -p option also works with -v/-V.jilles2010-12-011-2/+3
| | | | This was implemented in r201343.
* sh: Add printf builtin.jilles2010-11-191-1/+5
| | | | | | | | | | | | | | | | | 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.
* sh(1): Document r214304 (special builtin is illegal function name).jilles2010-11-121-0/+1
|
* sh(1): Update for r214492. "${v+"hi}there"}".jilles2010-11-121-5/+8
| | | | | The part hi}there is not a quoted string but nevertheless the closing brace does not terminate the expansion.
* sh(1): Modernize the introduction a bit.jilles2010-11-121-12/+5
| | | | | | 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.
* sh(1): Correct synopsis and make precise how $0 is set.jilles2010-10-311-4/+24
| | | | | | In particular, the extra argument to set $0 with -c was not documented. MFC after: 1 week
* sh(1): Clarify subshells/processes for pipelines.jilles2010-10-161-10/+8
| | | | | | | | | 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
* sh(1): Remove xrefs for expr(1) and getopt(1).jilles2010-09-101-3/+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
* sh(1): Add a brief summary of arithmetic expressions.jilles2010-08-221-5/+36
|
* sh: Forget about terminated background processes sooner.jilles2010-06-291-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | 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
* sh(1): Rework documentation of shell variables.jilles2010-05-241-87/+118
| | | | | | | | | * 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.
* sh(1): Improve wording of 'Special Parameters' section.jilles2010-05-241-7/+3
|
* sh(1): Fix "reserved word" vs "keyword" inconsistency.jilles2010-05-091-9/+9
| | | | | Use "keyword" everywhere, like the output of the 'type' builtin, and only mention "reserved word" once to say it is the same thing.
* sh: Automatically enable -o emacs in interactive shells with terminals.jilles2010-04-051-2/+3
| | | | | | | 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.
* sh: Document the expansion changes in the man page.jilles2010-04-041-2/+20
| | | | | | | | 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.
* sh: Improve the command builtin:jilles2010-03-061-4/+6
| | | | | | | | * avoid unnecessary fork * allow executing builtins via command * executing a special builtin via command removes its special properties Obtained from: NetBSD (parts)
* sh(1): document ulimit -w (swapuse rlimit).jilles2009-12-311-2/+5
| | | | MFC after: 1 week
* sh(1): Correct two places where "$@" lacked necessary quotes.jilles2009-12-311-2/+2
| | | | MFC after: 1 week
* sh: Exempt $@ and $* from set -ujilles2009-10-241-2/+5
| | | | | | | | 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).
* Clarify quoting of word in ${v=word} in sh(1).jilles2009-10-071-0/+3
|
* Mention that NUL characters are not allowed in sh(1) input.jilles2009-09-201-0/+4
| | | | | | | | 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
* Designate special builtins as such in command -V and type.jilles2009-06-241-3/+11
| | | | | | Also document various properties of special builtins that we implement. Approved by: ed (mentor) (implicit)
OpenPOWER on IntegriCloud