summaryrefslogtreecommitdiffstats
path: root/bin/sh
Commit message (Collapse)AuthorAgeFilesLines
...
* sh: Fix confusing behaviour if chdir succeeded but getcwd failed in cd -P.jilles2010-11-221-2/+5
| | | | | | If getcwd fails, do not treat this as an error, but print a warning and unset PWD. This is similar to the behaviour when starting the shell in a directory whose name cannot be determined.
* Fix some more warnings found by clang.brucec2010-11-221-0/+1
|
* sh: Remove the check that alpha/name/in_name chars are not CTL* bytes.jilles2010-11-201-3/+3
| | | | | | | | Since is_alpha/is_name/is_in_name were made ASCII-only, this can no longer happen. Additionally, the check was wrong because it did not include the new CTLQUOTEEND.
* sh: Code size optimizations to buffered output.jilles2010-11-207-34/+39
| | | | | | This is mainly less use of the outc macro. No functional change is intended, but code size is about 2K less on i386.
* sh: Add printf builtin.jilles2010-11-193-4/+9
| | | | | | | | | | | | | | | | | 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: Add binary buffered output for use by the printf builtin.jilles2010-11-143-10/+16
|
* sh: Update the suspend example for the change of the job control flagjilles2010-11-131-1/+1
| | | | | | from -j to -m, many years ago. Due to r215266, this function now actually works.
* sh: Do the additional actions if 'local -' restore changes -i/-m/-E/-V.jilles2010-11-131-0/+1
| | | | | | | Example: f() { local -; set +m; }; f caused failure to execute external programs because the job control tty fd was not opened.
* 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: Remove unused man page for echo builtin.jilles2010-11-121-114/+0
| | | | | | | | | | | | | The information in sh(1) about the echo builtin is equivalent, though less extensive. The echo(1) man page (bin/echo/echo.1) is different. Unfortunately, sh's echo builtin and /bin/echo have gone out of sync and this probably cannot be fixed any more. Reported by: uqs (list of untouched files) MFC after: 1 week
* 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: Fix some issues with aliases and case, by importing dash checkkwd code.jilles2010-11-021-50/+49
| | | | | | | | | | | This moves the function of the noaliases variable into the checkkwd variable. This way it is properly reset on errors and aliases can be used normally in the commands for each case (the case labels recognize the keyword esac but no aliases). The new code is clearer as well. Obtained from: dash
* 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: Reindent evaltree().jilles2010-10-311-76/+76
|
* sh: Use iteration instead of recursion to evaluate semicolon lists.jilles2010-10-312-15/+27
| | | | | This reduces CPU and memory usage when executing long lists (such as long functions).
* sh: Tweak some string constants to reduce code size.jilles2010-10-294-5/+5
| | | | | * Reduce some needless differences. * Shorten some error messages that should not happen.
* sh: Reject function names ending in one of !%*+-=?@}~jilles2010-10-291-1/+5
| | | | | | | | | These do something else in ksh: name=(...) is an array or compound variable assignment and the others are extended patterns. This is the last patch of the ones tested in the exp run. Exp-run done by: pav (with some other sh(1) changes)
* sh: Detect various additional errors in the parser.jilles2010-10-291-3/+3
| | | | | | | | | | | | | Apart from detecting breakage earlier or at all, this also fixes a segfault in the testsuite. The "handling" of the breakage left an invalid internal representation in some cases. Examples: echo a; do echo b echo `) echo a` echo `date; do do do` Exp-run done by: pav (with some other sh(1) changes)
* sh: Error out on various specials/keywords in the wrong place in backticks.jilles2010-10-291-16/+16
| | | | | | | | Example: echo `date)` Exp-run done by: pav (with some other sh(1) changes) Obtained from: NetBSD (Christos Zoulas, NetBSD PR 11317)
* sh: Fix some issues with CTL* bytes and ${var#pat}.jilles2010-10-291-14/+13
| | | | | | | | | | | | | | subevalvar() incorrectly assumed that CTLESC bytes were present iff the expansion was quoted. However, they are present iff various processing such as word splitting is to be done later on. Example: v=@$e@$e@$e@ y="${v##*"$e"}" echo "$y" failed if $e contained the magic CTLESC byte. Exp-run done by: pav (with some other sh(1) changes)
* sh: Do IFS splitting on word in ${v+word} and ${v-word}.jilles2010-10-295-14/+43
| | | | | | | | | | | | | | | | | The code is inspired by NetBSD sh somewhat, but different because we preserve the old Almquist/Bourne/Korn ability to have an unquoted part in a quoted ${v+word}. For example, "${v-"*"}" expands to $v as a single field if v is set, but generates filenames otherwise. Note that this is the only place where we split text literally from the script (the similar ${v=word} assigns to v and then expands $v). The parser must now add additional markers to allow the expansion code to know whether arbitrary characters in substitutions are quoted. Example: for i in ${$+a b c}; do echo $i; done Exp-run done by: pav (with some other sh(1) changes)
* sh: Only accept a '}' inside ${v+-=?...} if double-quote state matches.jilles2010-10-281-4/+4
| | | | | | | | | | | | | If double-quote state does not match, treat the '}' literally. This ensures double-quote state remains the same before and after a ${v+-=?...} which helps with expand.c. It makes things like ${foo+"\${bar}"} which I have seen in the wild work as expected. Exp-run done by: pav (with some other sh(1) changes)
* sh: Make double-quotes quote a '}' inside ${v#...} and ${v%...}.jilles2010-10-281-1/+2
| | | | | Exp-run done by: pav (with some other sh(1) changes) PR: bin/57554
* sh: Ignore double-quotes in arithmetic rather than treating them as quotes.jilles2010-10-242-5/+5
| | | | | | | | This provides similar behaviour, but allows a simpler parser. This changes r206473. Exp-run done by: pav (with some other sh(1) changes)
* sh: Do not allow overriding a special builtin with a function.jilles2010-10-241-0/+5
| | | | | | | | | | | | | | | | | This is a syntax error. POSIX does not say explicitly whether defining a function with the same name as a special builtin is allowed, but it does say that it is impossible to call such a function. A special builtin can still be overridden with an alias. This commit is part of a set of changes that will ensure that when something looks like a special builtin to the parser, it is one. (Not the other way around, as it remains possible to call a special builtin named by a variable or other substitution.) Exp-run done by: pav (with some other sh(1) changes)
* sh: Make sure defined functions can actually be called.jilles2010-10-241-3/+7
| | | | | | | | | | | | | | | | | Add some conservative checks on function names: - Disallow expansions or quoting characters; these can only be called via strange control characters - Disallow '/'; these functions cannot be called anyway, as exec.c assumes they are pathnames - Make the CTL* bytes work properly in function names. These are syntax errors. POSIX does not require us to support more than names (letters, digits and underscores, not starting with a digit), but I do not want to restrict it that much at this time. Exp-run done by: pav (with some other sh(1) changes)
* sh: Check whether dup2 was successful for >&FD and <&FD.jilles2010-10-241-2/+5
| | | | | | A failure (usually caused by FD not being open) is a redirection error. Exp-run done by: pav (with some other sh(1) changes)
* sh: Change ! within a pipeline to start a new pipeline instead.jilles2010-10-241-19/+11
| | | | | | | | | | | | | | This is how ksh93 treats ! within a pipeline and makes the ! in a | ! b | c negate the exit status of the pipeline, as if it were a | { ! b | c; } Side effect: something like f() ! a is now a syntax error, because a function definition takes a command, not a pipeline. Exp-run done by: pav (with some other sh(1) changes)
* 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: Use <stddef.h> rather than <sys/stddef.h>.jilles2010-10-161-1/+1
| | | | <sys/stddef.h> is only for the kernel and conflicts with <stddef.h>.
* We only need to look as far as '..' to find 'test/'.obrien2010-10-131-1/+1
|
* Do not assume in growstackstr() that a "precious" character will beobrien2010-10-133-9/+19
| | | | | | | | | | | | | | | | immediately written into the stack after the call. Instead let the caller manage the "space left". Previously, growstackstr()'s assumption causes problems with STACKSTRNUL() where we want to be able to turn a stack into a C string, and later pretend the NUL is not there. This fixes a bug in STACKSTRNUL() (that grew the stack) where: 1. STADJUST() called after a STACKSTRNUL() results in an improper adjust. This can be seen in ${var%pattern} and ${var%%pattern} evaluation. 2. Memory leak in STPUTC() called after a STACKSTRNUL(). Reviewed by: jilles
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroobrien2010-10-1321-227/+218
| | | | and its usage.
* If one wishes to set breakpoints of static the functions here, theyobrien2010-10-131-1/+1
| | | | | | cannot be inlined. Submitted by: jhb
* Make DEBUG traces 64-bit clean:jhb2010-10-132-20/+21
| | | | | | | | | - Use %t to print ptrdiff_t values. - Cast a ptrdiff_t value explicitly to int for a field width specifier. While here, sort includes. Submitted by: Garrett Cooper
* Suggest that DEBUG_FLAGS be used to enable extra debugging rather thanjhb2010-10-131-1/+1
| | | | | | | frobbing CFLAGS directly. DEBUG_FLAGS is something that can be specified on the make command line without having to edit the Makefile directly. Submitted by: Garrett Cooper
* Consistently use "STATIC" for all functions in order to be able to setobrien2010-10-1317-73/+77
| | | | | | breakpoints with in a debugger. And use naked "static" for variables. Noticed by: bde
* If DEBUG is 3 or greater, disable STATICization of functions.obrien2010-10-123-3/+8
| | | | Also correct the documented location of the trace file.
* Allow one to regression test 'sh' changes without having to installobrien2010-10-121-0/+3
| | | | a potentially bad /bin/sh first.
* sh: Add __dead2 to two functions that do not return.jilles2010-09-121-2/+2
| | | | | Apart from helping static analyzers, this also appears to reduce the size of the binary slightly.
* sh: Fix exit status if return is used within a loop condition.jilles2010-09-111-0/+2
|
* sh: Apply variable assignments left-to-right in bltinlookup().jilles2010-09-111-1/+5
| | | | | Example: HOME=foo HOME=bar cd
* 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: Fix 'read' if all chars before the first IFS char are backslash-escaped.jilles2010-09-081-0/+1
| | | | | | Backslash-escaped characters did not set the flag for a non-IFS character. MFC after: 2 weeks
* sh: Improve comments in expand.c.jilles2010-09-051-21/+37
|
* sh: Get rid of some magic numbers.jilles2010-09-041-2/+2
| | | | MFC after: 1 week
* sh: Do not use locale for determining if something is a name.jilles2010-09-031-5/+5
| | | | | | | | | | | This makes it impossible to use locale-specific characters in variable names. Names containing locale-specific characters make scripts only work with the correct locale setting. Also, they did not even work in many practical cases because multibyte character sets such as utf-8 are not supported. This also avoids weirdness if LC_CTYPE is changed in the middle of a script.
* sh: Remove remnants of '!!' to negate pattern.jilles2010-08-221-17/+2
| | | | | | | | This Almquist extension was disabled long ago. In pathname generation, components starting with '!!' were treated as containing wildcards, causing unnecessary readdir (which could fail, causing pathname generation to fail while it should not).
* sh(1): Add a brief summary of arithmetic expressions.jilles2010-08-221-5/+36
|
OpenPOWER on IntegriCloud