aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/sh.1
Commit message (Collapse)AuthorAgeFilesLines
* Fix description of the "\$" sequence for PS1Mateusz Piotrowski2020-07-061-3/+3
| | | | | | | | | | | | The manual page documents "\$" to expand to either "$" or "#" followed by a single space. In reality, the single space character is not appended. PR: 247791 Submitted by: kd-dev@pm.me MFC after: 7 days Notes: svn path=/head/; revision=362957
* sh: Add set -o pipefailJilles Tjoelker2019-02-241-5/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pipefail option allows checking the exit status of all commands in a pipeline more easily, at a limited cost of complexity in sh itself. It works similarly to the option in bash, ksh93 and mksh. Like ksh93 and unlike bash and mksh, the state of the option is saved when a pipeline is started. Therefore, even in the case of commands like A | B & a later change of the option does not change the exit status, the same way (A | B) & works. Since SIGPIPE is not handled specially, more work in the script is required for a proper exit status for pipelines containing commands such as head that may terminate successfully without reading all input. This can be something like ( cmd1 r=$? if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then exit 0 else exit "$r" fi ) | head PR: 224270 Relnotes: yes Notes: svn path=/head/; revision=344502
* Make sh(1) support \u in PS1. This removes one fork/exec on interactiveEdward Tomasz Napierala2019-01-241-1/+3
| | | | | | | | | | | | shell startup. Reviewed by: 0mp (man page), jilles MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D18790 Notes: svn path=/head/; revision=343399
* sh(1): Remove -c string from set builtin documentationJilles Tjoelker2018-12-081-3/+3
| | | | | | | | | Altering the -c string at run time does not make sense and is not possible. MFC after: 1 week Notes: svn path=/head/; revision=341725
* sh: Use 126 and 127 exit status for failures opening a scriptJilles Tjoelker2018-11-271-2/+6
| | | | | | | | | | This affects scripts named on the command line, named with a '.' special builtin and found via the PATH %func autoloading mechanism. PR: 231986 Notes: svn path=/head/; revision=341097
* Describe how to prevent *.core files from being created using ulimit.Mateusz Piotrowski2018-07-191-28/+24
| | | | | | | | | | | While here, pet mandoc. Reviewed by: eadler (previous revision), jilles (previous revision), mat (mentor) Approved by: manpages (jilles), mat (mentor) Differential Revision: https://reviews.freebsd.org/D15609 Notes: svn path=/head/; revision=336483
* sh(1): Markup and spelling fixesJilles Tjoelker2017-12-231-2/+2
| | | | Notes: svn path=/head/; revision=327121
* Fix mandoc -Tlint warnings in bin/Benjamin Kaduk2017-12-071-1/+1
| | | | | | | | | | | Many style-level issues are still reported. Submitted by: Yuri Pankov <yuripv@gmx.com> Reviewed by: jilles (previous revision) Differential Revision: https://reviews.freebsd.org/D13334 Notes: svn path=/head/; revision=326651
* sh: Ignore error when cd writes the directory actually switched to.Jilles Tjoelker2017-06-251-0/+5
| | | | | | | | | | | | If CDPATH is used non-trivially or the operand is "-", cd writes the directory actually switched to. (We currently do this only in interactive shells, but POSIX requires this in non-interactive shells as well.) As mentioned in Austin group bug #1045, cd shall not return an error while leaving the current directory changed. Therefore, ignore any write error. Notes: svn path=/head/; revision=320340
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Remove empty LiBaptiste Daroussin2017-02-111-1/+1
| | | | | | | | Reported by: make manlint MFC after: 2 days Notes: svn path=/head/; revision=313660
* sh: Do not import IFS's value from the environment.Jilles Tjoelker2016-10-081-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | Per Austin group issue #884, always set IFS to $' \t\n'. As before, IFS will be exported iff it was in the environment. Most shells (e.g. bash, ksh93 and mksh) already did this. This change improves predictability, in that scripts can simply rely on the default value. However, the effect on security is little, since applications should not be calling the shell with attacker-controlled environment variable names in the first place and other security-sensitive variables such as PATH should be and are imported by the shell. When using a new sh with an old (before 10.2) libc wordexp(), IFS is no longer passed on. Otherwise, wordexp() continues to pass along IFS from the environment per its documentation. Discussed with: pfg Relnotes: yes Notes: svn path=/head/; revision=306843
* Clarify the explanations for the hostname and FQDN entries.Warren Block2016-05-311-3/+3
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=301007
* Match the descriptions of the \H and \h prompt string sequences to reality.Don Lewis2016-05-251-3/+3
| | | | | | | | | | They were swapped. X-Confirmed by: jilles MFC after: 1 week Notes: svn path=/head/; revision=300642
* Fix handling of umtxp resource limit in sh(1)/ulimit(1), limits(1), addKonstantin Belousov2016-03-121-1/+6
| | | | | | | | | | | login.conf(5) support. Reviewed by: jilles Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D5610 Notes: svn path=/head/; revision=296723
* sh(1): Document 'cd -'.Jilles Tjoelker2016-01-301-6/+19
| | | | | | | | This reflects the changes in r294649 and can therefore not be MFCed by itself. Notes: svn path=/head/; revision=295083
* sh: Add set -o nolog.Jilles Tjoelker2015-08-291-2/+9
| | | | | | | | | | | | | POSIX requires this to prevent entering function definitions in history but this implementation does nothing except retain the option's value. In ksh88, function definitions were usually entered in the history file, even when they came from ~/.profile and the $ENV file, to allow displaying their definitions. This is also the first option that does not have a letter. Notes: svn path=/head/; revision=287296
* sh(1): libedit has supported multibyte encodings for a while.Jilles Tjoelker2015-07-111-4/+2
| | | | Notes: svn path=/head/; revision=285385
* sh: Fix the trap builtin to be POSIX-compliant for 'trap exit SIG' and 'trap ↵Bryan Drewery2015-04-181-3/+2
| | | | | | | | | | | | | | | | | | | | n n...'. The parser considered 'trap exit INT' to reset the default for both EXIT and INT. This beahvior is not POSIX compliant. This was avoided if a value was specified for 'exit', but then disallows exiting with the signal received. A possible workaround is using ' exit'. However POSIX does allow this type of behavior if the parameters are all integers. Fix the handling for this and clarify its support in the manpage since it is specifically allowed by POSIX. Differential Revision: https://reviews.freebsd.org/D2325 Reviewed by: jilles MFC after: 2 weeks Notes: svn path=/head/; revision=281718
* sh: Add details about importing the environment and initializing OPTIND.Jilles Tjoelker2015-02-221-7/+14
| | | | Notes: svn path=/head/; revision=279188
* sh(1): Add/improve information about exit status of commands.Jilles Tjoelker2014-11-141-10/+24
| | | | Notes: svn path=/head/; revision=274515
* sh(1): Mention portability issue with shifting zero positional parameters.Jilles Tjoelker2014-11-071-2/+3
| | | | | | | | | Per Austin Group issue #459, shifting zero positional parameters may or may not be considered an operand error (which causes the shell to exit in most cases). Notes: svn path=/head/; revision=274254
* sh(1): Clarify that assignments before commands do not affect expansions.Jilles Tjoelker2014-09-211-2/+3
| | | | | | | | PR: 193759 MFC after: 1 week Notes: svn path=/head/; revision=271936
* sh: Allow enabling job control without a tty in non-interactive mode.Jilles Tjoelker2014-09-041-1/+7
| | | | | | | | If no tty is available, 'set -m' is still useful to put jobs in their own process groups. Notes: svn path=/head/; revision=271144
* sh: Add -h option to SYNOPSISDaichi GOTO2014-02-251-3/+3
| | | | | | | | Reviewed by: jilles MFC after: soon Notes: svn path=/head/; revision=262467
* sh: Allow aliases to force alias substitution on the following word.Jilles Tjoelker2014-01-261-1/+15
| | | | | | | | | | | If an alias's value ends with a space or tab, the next word is also checked for aliases. This is a POSIX feature. It is useful with utilities like command and nohup (alias them to themselves followed by a space). Notes: svn path=/head/; revision=261192
* sh(1): Discourage use of -e.Jilles Tjoelker2014-01-031-2/+8
| | | | | | | | Also, do not say that ! before a pipeline is an operator, because it is syntactically a keyword. Notes: svn path=/head/; revision=260246
* sh(1),limits(1): Document kqueues (-k) rlimit.Jilles Tjoelker2013-11-011-2/+7
| | | | Notes: svn path=/head/; revision=257506
* sh: Make return return from the closest function or dot script.Jilles Tjoelker2013-09-041-2/+4
| | | | | | | | | | | | | | | | Formerly, return always returned from a function if it was called from a function, even if there was a closer dot script. This was for compatibility with the Bourne shell which only allowed returning from functions. Other modern shells and POSIX return from the function or the dot script, whichever is closest. Git 1.8.4's rebase --continue depends on the POSIX behaviour. Reported by: Christoph Mallon, avg Notes: svn path=/head/; revision=255215
* sh(1): A subshell environment has its own rlimits (ulimit).Jilles Tjoelker2013-06-141-1/+4
| | | | | | | | | This has always been the case and is intended (just like cd). This matches Austin group issue #706. Notes: svn path=/head/; revision=251763
* sh(1): Document new features in wait builtin.Jilles Tjoelker2013-06-051-4/+9
| | | | | | | PR: 176916 Notes: svn path=/head/; revision=251432
* sh: Improve error handling in read builtin:Jilles Tjoelker2013-05-031-2/+9
| | | | | | | | | | | | | | | * If read -t times out, return status as if interrupted by SIGALRM (formerly 1). * If a trapped signal interrupts read, return status 128+sig (formerly 1). * If [EINTR] occurs but there is no trap, retry the read (for example because of a SIGWINCH in interactive mode). * If a read error occurs, write an error message and return status 2. As before, a variable assignment error returns 2 and discards the remaining data read. Notes: svn path=/head/; revision=250214
* Document a few expansions for the $PS1 and $PS2 environmental variables.Joel Dahl2013-04-211-1/+25
| | | | | | | | | PR: 173410 Submitted by: Derek Wood <ddwood@outlook.com> Reviewed by: jilles Notes: svn path=/head/; revision=249740
* Minor mdoc fix.Joel Dahl2013-03-291-1/+1
| | | | Notes: svn path=/head/; revision=248870
* sh(1): Mention possible ambiguities with $(( and ((.Jilles Tjoelker2013-03-241-1/+14
| | | | | | | | | | | | In some other shells, things like $((a);(b)) are command substitutions. Also, there are shells that have an extension ((ARITH)) that evaluates an arithmetic expression and returns status 1 if the result is zero, 0 otherwise. This extension may lead to ambiguity with two subshells starting in sequence. Notes: svn path=/head/; revision=248692
* Add FILES section.Joel Dahl2013-01-221-2/+14
| | | | | | | Discussed with: jilles Notes: svn path=/head/; revision=245805
* Change the $ENV example to use .shrc instead of .shinit. This is consistentJoel Dahl2013-01-201-3/+3
| | | | | | | | | with what we use in /usr/share/skel/dot.profile. Discussed with: jilles Notes: svn path=/head/; revision=245699
* sh: Simplify cd-hash interaction.Jilles Tjoelker2013-01-141-5/+1
| | | | | | | | | | | Instead of rechecking relative paths for all hashed utilities after a cd, track if any utility in cmdtable depends on a relative path in PATH. If there is such a utility, cd clears the entire table. As a result, the '*' in hash no longer happens. Notes: svn path=/head/; revision=245426
* mdoc: don't nest displays. The markup here isn't adding anything anyway.Joel Dahl2012-10-141-2/+2
| | | | | | | | | Fixes a mandoc lint warning. Discussed with: brueffer, Jason McIntyre <jmc@kerhand.co.uk> Notes: svn path=/head/; revision=241544
* Minor mdoc fix.Joel Dahl2012-09-111-1/+2
| | | | Notes: svn path=/head/; revision=240369
* sh: Expand assignment-like words specially for export/readonly/local.Jilles Tjoelker2012-07-151-1/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Examples: export x=~ now expands the tilde local y=$1 is now safe, even if $1 contains IFS characters or metacharacters. For a word to "look like an assignment", it must start with a name followed by an equals sign, none of which may be quoted. The special treatment applies when the first word (potentially after "command") is "export", "readonly" or "local". There may be quoting characters but no expansions. If "local" is overridden with a function there is no special treatment ("export" and "readonly" cannot be overridden with a function). If things like local arr=(1 2 3) are ever allowed in the future, they cannot call a "local" function. This would either be a run-time error or it would call the builtin. This matches Austin Group bug #351, planned for the next issue of POSIX.1. PR: bin/166771 Notes: svn path=/head/; revision=238468
* Minor mdoc nits.Joel Dahl2012-05-131-2/+2
| | | | Notes: svn path=/head/; revision=235400
* mdoc: fix column names, indentation, column separation within each row, andJoel Dahl2012-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 Notes: svn path=/head/; revision=233992
* Remove trailing whitespace per mdoc lint warningEitan Adler2012-03-291-1/+1
| | | | | | | | | | Disussed with: gavin No objection from: doc Approved by: joel MFC after: 3 days Notes: svn path=/head/; revision=233648
* Remove superfluous paragraph macro.Joel Dahl2012-03-251-1/+0
| | | | Notes: svn path=/head/; revision=233457
* sh(1): Improve documentation of field splitting.Jilles Tjoelker2011-11-051-11/+55
| | | | Notes: svn path=/head/; revision=227122
* sh(1): Extend documentation about subshells.Jilles Tjoelker2011-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. Notes: svn path=/head/; revision=223909
* sh(1): Improve documentation of shell patterns:Jilles Tjoelker2011-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 Notes: svn path=/head/; revision=223522
* sh(1): Document the case command better.Jilles Tjoelker2011-06-241-2/+13
| | | | | | | | Suggested by: netchild Reviewed by: gjb Notes: svn path=/head/; revision=223517
* sh: Add do-nothing -h option.Jilles Tjoelker2011-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". Notes: svn path=/head/; revision=223281