aboutsummaryrefslogtreecommitdiff
path: root/bin
Commit message (Collapse)AuthorAgeFilesLines
* Rename ki_ocomm to ki_tdname and OCOMMLEN to TDNAMLEN.Bjoern A. Zeeb2011-07-182-9/+9
| | | | | | | | | | | | Provide backward compatibility defines under BURN_BRIDGES. Suggested by: jhb Reviewed by: emaste Sponsored by: Sandvine Incorporated Approved by: re (kib) Notes: svn path=/head/; revision=224199
* 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
* Fix style, since this file has just been touched in a major way.Stefan Eßer2011-07-091-96/+75
| | | | | | | No actual code changes. Notes: svn path=/head/; revision=223883
* Some refactoring for easier maintenance of the code. This is a follow-upStefan Eßer2011-07-091-146/+69
| | | | | | | | | to re-establishment of 64bit arithmetic, but is committed separately, to not obscure that conversion. This commit does not change the observed behaviour of expr in any way. Style will be fixed in a follow-up commit. Notes: svn path=/head/; revision=223882
* Make /bin/expr support 64bit numeric range and range checks by default,Stefan Eßer2011-07-092-140/+152
| | | | | | | | | | | | | | | | | | | | | | | | | | | again. This brings back the behaviour of expr in FreeBSD-4, which had been reverted due to an assumed incompatbility with POSIX.1 for FreeBSD-5. This issue has been discussed in the freebsd-standards list, and the consensus was, that POSIX.1 is in fact not violated by this extension, since it affects only cases of POSIX undefined behaviour (overflow of signed long). Other operating systems did upgrade their versions of expr to support 64bit range, after it had been initially brought to FreeBSD. They have used it for a decade without problems, meanwhile. The -e option is retained, but it will only select less strict checking of numeric parameters (leading white-space, leading "+" are allowed and skipped, an empty string is considered to represent 0 in numeric context.) The call of check_utility_compat() as a means of establishing backwards compatibility with FreeBSD-4 is considered obsolete, but preserved in this commit. It is expected to be removed in a later revision of this file. Reviewed by: bde, das, jilles MFC after: 2 month (those parts that do not violate POLA) Notes: svn path=/head/; revision=223881
* Bump date after the previous commit.Sergey Kandaurov2011-07-011-1/+1
| | | | Notes: svn path=/head/; revision=223709
* Update and sort the list of the available keywords.Sergey Kandaurov2011-07-011-6/+8
| | | | Notes: svn path=/head/; revision=223708
* sh: Include <limits.h> instead of non-standard <sys/limits.h>.Jilles Tjoelker2011-06-261-1/+1
| | | | Notes: svn path=/head/; revision=223580
* 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
* Remove duplicated header filesKevin Lo2011-06-242-2/+0
| | | | Notes: svn path=/head/; revision=223494
* Make ``realpath'' behave like ``realpath .''.Ruslan Ermilov2011-06-212-11/+15
| | | | Notes: svn path=/head/; revision=223372
* sh: Remove special support for background simple commands.Jilles Tjoelker2011-06-183-9/+5
| | | | | | | It expands the arguments in the parent shell process, which is incorrect. Notes: svn path=/head/; revision=223282
* sh: Add do-nothing -h option.Jilles Tjoelker2011-06-182-2/+8
| | | | | | | | | | | | | 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
* sh: Add case statement fallthrough (with ';&' instead of ';;').Jilles Tjoelker2011-06-175-7/+28
| | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=223186
* sh: Skip variables with invalid names in "set", "export -p", "readonly -p".Jilles Tjoelker2011-06-171-0/+13
| | | | | | | This ensures the output of these commands is valid shell input. Notes: svn path=/head/; revision=223183
* sh: Reduce unnecessary forks with eval.Jilles Tjoelker2011-06-161-1/+2
| | | | | | | | | | | | | The eval special builtin now runs the code with EV_EXIT if it was run with EV_EXIT itself. In particular, this eliminates one fork when a command substitution contains an eval command that ends with an external program or a subshell. This is similar to what r220978 did for functions. Notes: svn path=/head/; revision=223163
* sh: Add support for named character classes in bracket expressions.Jilles Tjoelker2011-06-152-2/+48
| | | | | | | | Example: case x in [[:alpha:]]) echo yes ;; esac Notes: svn path=/head/; revision=223120
* Add "gid" and "group" keywords to display the effective group IDEdward Tomasz Napierala2011-06-144-2/+34
| | | | | | | | | | and effective group name. Also, add "egid", "egroup" and "euid" aliases. PR: bin/146331 Submitted by: Jeremie Le Hen <jeremie at le-hen dot org> Notes: svn path=/head/; revision=223086
* sh: Fix duplicate prototypes for builtins.Jilles Tjoelker2011-06-1323-41/+14
| | | | | | | | | Have mkbuiltins write the prototypes for the *cmd functions to builtins.h instead of builtins.c and include builtins.h in more .c files instead of duplicating prototypes for *cmd functions in other headers. Notes: svn path=/head/; revision=223060
* sh: Save/restore changed variables in optimized command substitution.Jilles Tjoelker2011-06-127-89/+25
| | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=223024
* sh: Fix locale-dependent ranges in bracket expressions.Jilles Tjoelker2011-06-121-4/+4
| | | | | | | | | | | When I added UTF-8 support in r221646, the LC_COLLATE-based ordering broke because of sign extension of char. Because of libc restrictions, this does not work for UTF-8. For UTF-8 locales, ranges always use character code order. Notes: svn path=/head/; revision=223010
* sh: Read .profile from the home directory (or / if HOME is not set).Jilles Tjoelker2011-06-121-1/+1
| | | | | | | | | | | | | In most cases, login shells are started from the home directory, but not in all, such as xterm -ls. This commit depends on r222957 for read_profile() performing parameter expansion. PR: bin/50569 Notes: svn path=/head/; revision=223005
* sh: Do parameter expansion on ENV before using it.Jilles Tjoelker2011-06-102-7/+13
| | | | | | | | | This is required by POSIX, and allows things like ENV=\$HOME/.shrc. Note that tilde expansion is explicitly not performed. Notes: svn path=/head/; revision=222957
* sh: Do parameter expansion before printing PS4 (set -x).Jilles Tjoelker2011-06-095-4/+51
| | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=222907
* sh: Fix $? in heredocs on simple commands.Jilles Tjoelker2011-06-051-1/+2
| | | | | | | PR: bin/41410 Notes: svn path=/head/; revision=222716
* sh: Improve error message if the script cannot be opened.Jilles Tjoelker2011-06-041-2/+4
| | | | | | | Avoid "<nosuchfile>: cannot open <nosuchfile>: ...". Notes: svn path=/head/; revision=222699
* sh: Reduce more needless differences between error messages.Jilles Tjoelker2011-06-044-5/+5
| | | | Notes: svn path=/head/; revision=222684
* sh: Honour -n while processing -c string.Jilles Tjoelker2011-06-041-1/+1
| | | | Notes: svn path=/head/; revision=222676
* sh: Remove the "exp" builtin.Jilles Tjoelker2011-05-272-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | The "exp" builtin is undocumented, non-standard and not very useful. If exp's return value is not used, something like VAR=$(exp EXPRESSION) is equivalent to VAR=$((EXPRESSION)) except that errors in the expression are fatal and quoting special characters is not needed in the latter case. If exp's return value is used, something like if exp EXPRESSION >/dev/null can be replaced by if [ $((EXPRESSION)) -ne 0 ] with similar differences. The exp-run showed that "let" is close enough to bash's and ksh's builtin that removing it would break a few ports. Therefore, "let" remains in 9.x. PR: bin/104432 Exp-run done by: pav (with some other sh(1) changes) Notes: svn path=/head/; revision=222386
* sh: Correct criterion for using CDPATH in cd.Jilles Tjoelker2011-05-271-1/+4
| | | | | | | | | | CDPATH should be ignored not only for pathnames starting with '/' but also for pathnames whose first component is '.' or '..'. The man page already describes this behaviour. Notes: svn path=/head/; revision=222381
* sh: Various updates to the TOUR document.Jilles Tjoelker2011-05-271-29/+8
| | | | Notes: svn path=/head/; revision=222362
* sh: Fix unquoted $@/$* if IFS=''.Jilles Tjoelker2011-05-271-2/+5
| | | | | | | | | If IFS is null, unquoted $@/$* should still expand to separate words. This differs from quoted $@ (which does not depend on IFS) in that pathname generation is performed and empty words are removed. Notes: svn path=/head/; revision=222361
* sh: Show errno messages in cd.Jilles Tjoelker2011-05-251-1/+4
| | | | Notes: svn path=/head/; revision=222292
* sh: Remove obsolete token type TENDBQUOTE.Jilles Tjoelker2011-05-221-1/+0
| | | | | | | | This token type was related to Almquist's original version of backquotes that could not nest and fell into disuse fairly soon. Notes: svn path=/head/; revision=222182
* Fix some typos under bin/Ulrich Spörlein2011-05-223-4/+4
| | | | | | | Found by: codespell Notes: svn path=/head/; revision=222178
* Fix a bunch of typos and a couple of whitespace nits.Ulrich Spörlein2011-05-2212-47/+47
| | | | | | | Helped by: codespell and vim's spellchecker Notes: svn path=/head/; revision=222177
* sh: Fix bss-based buffer overflow in . builtin.Jilles Tjoelker2011-05-221-4/+7
| | | | | | | | | | | | | | If the length of a directory in PATH together with the given filename exceeded FILENAME_MAX (which may happen even for pathnames that work), a static buffer was overflown. The static buffer is unnecessary, we can use the stalloc() stack. Obtained from: NetBSD MFC after: 1 week Notes: svn path=/head/; revision=222173
* sh: Expand aliases after assignments and redirections.Jilles Tjoelker2011-05-214-12/+29
| | | | Notes: svn path=/head/; revision=222165
* sh: Implement the cd -e flag proposed for the next POSIX issue.Jilles Tjoelker2011-05-202-10/+28
| | | | | | | | | | | | 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. Notes: svn path=/head/; revision=222154
* sh: Allow terminating a heredoc with a terminator at EOF without a newline.Jilles Tjoelker2011-05-201-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | This is sometimes used with eval or old-style command substitution, and most shells other than ash derivatives allow it. It can also be used with scripts that violate POSIX's requirement on the application that they end in a newline (scripts must be text files except that line length is unlimited). Example: v=`cat <<EOF foo EOF` echo $v This commit does not add support for the similar construct with new-style command substitution, like v=$(cat <<EOF foo EOF) This continues to require a newline after the terminator. Notes: svn path=/head/; revision=222134
* Spelling in P_HADTHREADS.Sergey Kandaurov2011-05-201-1/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=222130
* Fix the description of the "paddr" keyword. It shows a processSergey Kandaurov2011-05-201-1/+1
| | | | | | | | | pointer just like a dublicating "uprocp". MFC after: 1 week Notes: svn path=/head/; revision=222127
* sh: Minor optimization to output from ulimit/export/readonly.Jilles Tjoelker2011-05-152-8/+7
| | | | | | | No functional change is intended. Notes: svn path=/head/; revision=221975
* sh: Avoid close(-1) when evaluating a multi-command pipeline.Jilles Tjoelker2011-05-151-1/+2
| | | | | | | Valgrind complains about this. Notes: svn path=/head/; revision=221970
* Update sticky(7) cross references.Sergey Kandaurov2011-05-132-7/+7
| | | | | | | | PR: docs/124468 X-MFC with: r218998 Notes: svn path=/head/; revision=221845
* sh: Add \u/\U support (in $'...') for UTF-8.Jilles Tjoelker2011-05-085-4/+37
| | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=221669
* sh: Optimize variable code by storing the length of the name.Jilles Tjoelker2011-05-082-124/+125
| | | | | | | Obtained from: NetBSD Notes: svn path=/head/; revision=221668
* sh(1): Update BUGS section for UTF-8 support.Jilles Tjoelker2011-05-081-2/+7
| | | | Notes: svn path=/head/; revision=221660
* sh: Add UTF-8 support to pattern matching.Jilles Tjoelker2011-05-081-12/+50
| | | | | | | | | | | | | ?, [...] patterns match codepoints instead of bytes. They do not match invalid sequences. [...] patterns must not contain invalid sequences otherwise they will not match anything. This is so that ${var#?} removes the first codepoint, not the first byte, without putting UTF-8 knowledge into the ${var#pattern} code. However, * continues to match any string and an invalid sequence matches an identical invalid sequence. (This differs from fnmatch(3).) Notes: svn path=/head/; revision=221646