History log of /freebsd-9.3-release/bin/sh/eval.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 267654 19-Jun-2014 gjb

Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 264423 13-Apr-2014 jilles

MFC r238468: sh: Expand assignment-like words specially for
export/readonly/local.

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.

As for the MFC, it is easy to depend on this feature inadvertently, and
adding this fixes a regression from stable/8 that may be apparent in things
like
local x=${y+a @}.

PR: bin/166771
Relnotes: yes


# 249242 07-Apr-2013 jilles

MFC r230998,r233792: sh: Use vfork in a few common cases.

This uses vfork() for simple commands and command substitutions containing a
single simple command, invoking an external program under certain conditions
(no redirections or variable assignments, non-interactive shell, no job
control). These restrictions limit the amount of code executed in a vforked
child.

Various incarnations of this patch have been shown to bring performance
improvements:
http://lists.freebsd.org/pipermail/freebsd-hackers/2012-January/037581.html

The use of vfork() can be disabled by setting a variable named
SH_DISABLE_VFORK.


# 231085 06-Feb-2012 dumbbell

MFC r230212:
sh: Fix execution of multiple statements in a trap when evalskip is set

Before this fix, only the first statement of the trap was executed if
evalskip was set. This is for example the case when:
o "-e" is set for this shell
o a trap is set on EXIT
o a function returns 1 and causes the script to abort

Reviewed by: jilles
Sponsored by: Yakaz (http://www.yakaz.com)


# 230625 27-Jan-2012 jilles

MFC r228937: sh: Do not force special builtins non-special in optimized
command substitition.

This is not necessary: errors are already caught in evalbackcmd() and
forcelocal handles changes to variables.

Note that this depends on r223024.


# 225736 22-Sep-2011 kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by: re (implicit)


# 223282 18-Jun-2011 jilles

sh: Remove special support for background simple commands.

It expands the arguments in the parent shell process, which is incorrect.


# 223186 17-Jun-2011 jilles

sh: Add case statement fallthrough (with ';&' instead of ';;').

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.


# 223163 16-Jun-2011 jilles

sh: Reduce unnecessary forks with eval.

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.


# 223024 12-Jun-2011 jilles

sh: Save/restore changed variables in optimized command substitution.

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.


# 222907 09-Jun-2011 jilles

sh: Do parameter expansion before printing PS4 (set -x).

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.


# 222716 05-Jun-2011 jilles

sh: Fix $? in heredocs on simple commands.

PR: bin/41410


# 222676 04-Jun-2011 jilles

sh: Honour -n while processing -c string.


# 222165 21-May-2011 jilles

sh: Expand aliases after assignments and redirections.


# 221970 15-May-2011 jilles

sh: Avoid close(-1) when evaluating a multi-command pipeline.

Valgrind complains about this.


# 221027 25-Apr-2011 jilles

sh: Set $? to 0 for background commands.

For backgrounded pipelines and subshells, the previous value of $? was being
preserved, which is incorrect.

For backgrounded simple commands containing a command substitution, the
status of the last command substitution was returned instead of 0.

If fork() fails, this is an error.


# 220978 23-Apr-2011 jilles

sh: Allow EV_EXIT through function calls, make {...} <redir more consistent.

If EV_EXIT causes an exit, use the exception mechanism to unwind
redirections and local variables. This way, if the final command is a
redirected command, an EXIT trap now executes without the redirections.

Because of these changes, EV_EXIT can now be inherited by the body of a
function, so do so. This means that a function no longer prevents a fork
before an exec being skipped, such as in
f() { head -1 /etc/passwd; }; echo $(f)

Wrapping a single builtin in a function may still cause an otherwise
unnecessary fork with command substitution, however.

An exit command or -e failure still invokes the EXIT trap with the
original redirections and local variables in place.

Note: this depends on SHELLPROC being gone. A SHELLPROC depended on
keeping the redirections and local variables and only cleaning up the
state to restore them.


# 218324 05-Feb-2011 jilles

sh: Remove clearcmdentry()'s now unused argument.


# 218306 04-Feb-2011 jilles

sh: Remove special code for shell scripts without magic number.

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.


# 217035 05-Jan-2011 jilles

sh: Do not call exitshell() from evalcommand() unless evalcommand() forked
itself.

This ensures that certain traps caused by builtins are executed.


# 216870 01-Jan-2011 jilles

sh: Check readonly status for assignments on regular builtins.

An error message is written, the builtin is not executed, nonzero exit
status is returned but the shell does not abort.

This was already checked for special builtins and external commands, with
the same consequences except that the shell aborts for special builtins.

Obtained from: NetBSD


# 216826 30-Dec-2010 jilles

sh: Avoid side effects from builtins in optimized command substitution.

Change the criterion for builtins to be safe to execute in the same process
in optimized command substitution from a blacklist of only cd, . and eval to
a whitelist.

This avoids clobbering the main shell environment such as by $(exit 4) and
$(set -x).

The builtins jobid, jobs, times and trap can still show information not
available in a child process; this is deliberately permitted. (Changing
traps is not.)

For some builtins, whether they are safe depends on the arguments passed to
them. Some of these are always considered unsafe to keep things simple; this
only harms efficiency a little in the rare case they are used alone in a
command substitution.


# 216778 28-Dec-2010 jilles

sh: Don't do optimized command substitution if expansions have side effects.

Before considering to execute a command substitution in the same process,
check if any of the expansions may have a side effect; if so, execute it in
a new process just like happens if it is not a single simple command.

Although the check happens at run time, it is a static check that does not
depend on current state. It is triggered by:
- expanding $! (which may cause the job to be remembered)
- ${var=value} default value assignment
- assignment operators in arithmetic
- parameter substitutions in arithmetic except ${#param}, $$, $# and $?
- command substitutions in arithmetic

This means that $((v+1)) does not prevent optimized command substitution,
whereas $(($v+1)) does, because $v might expand to something containing
assignment operators.

Scripts should not depend on these exact details for correctness. It is also
imaginable to have the shell fork if and when a side effect is encountered
or to create a new temporary namespace for variables.

Due to the $! change, the construct $(jobs $!) no longer works. The value of
$! should be stored in a variable outside command substitution first.


# 216761 28-Dec-2010 jilles

sh: Make expansion errors in optimized command substitution non-fatal.
Command substitutions consisting of a single simple command are executed in
the main shell process but this should be invisible apart from performance
and very few exceptions such as $(trap).


# 215783 23-Nov-2010 jilles

sh: Code size optimizations to "stack string" memory allocation:
* Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC.
* Add STPUTS macro (based on function) and use it instead of loops that add
nul-terminated strings to the stack string.

No functional change is intended, but code size is about 1K less on i386.


# 215567 20-Nov-2010 jilles

sh: Code size optimizations to buffered output.

This is mainly less use of the outc macro.

No functional change is intended, but code size is about 2K less on i386.


# 214600 31-Oct-2010 jilles

sh: Reindent evaltree().


# 214599 31-Oct-2010 jilles

sh: Use iteration instead of recursion to evaluate semicolon lists.
This reduces CPU and memory usage when executing long lists (such
as long functions).


# 214538 29-Oct-2010 jilles

sh: Tweak some string constants to reduce code size.

* Reduce some needless differences.
* Shorten some error messages that should not happen.


# 213811 13-Oct-2010 obrien

In the spirit of r90111, depend on c89 and remove the "STATIC" macro
and its usage.


# 213760 13-Oct-2010 obrien

Consistently use "STATIC" for all functions in order to be able to set
breakpoints with in a debugger. And use naked "static" for variables.

Noticed by: bde


# 212475 11-Sep-2010 jilles

sh: Fix exit status if return is used within a loop condition.


# 212214 04-Sep-2010 jilles

sh: Get rid of some magic numbers.

MFC after: 1 week


# 211287 13-Aug-2010 jilles

sh: Add a forgotten const.


# 210829 03-Aug-2010 jilles

sh: Return 0 from eval if no command was given.

This makes a difference if there is a command substitution.

To make this work, evalstring() has been changed to set exitstatus to 0 if
no command was executed (the string contained only whitespace).

Example:
eval $(false); echo $?
should print 0.


# 208630 28-May-2010 jilles

sh: Recognize "--" in . and exec.

Although "--" historically has not been required to be recognized for
certain special builtins that do not take options in POSIX, some other
implementations recognize options for them, requiring scripts to use "--" or
avoid operands starting with "-".

Operands starting with "-" can be avoided with eval by prepending a space,
and cannot occur with break, continue, exit, return and shift as they only
take numbers, nor with times as it does not take operands. With . and exec,
avoiding "-" is not so easy as it may require reimplementing the PATH
search; therefore the current proposal for POSIX is to require recognition
of "--" for them.

We continue to accept other strings starting with "-" as operands to . and
exec, and also "--" if it is alone to . (which would otherwise be invalid
anyway).


# 207783 08-May-2010 jilles

sh: Have only one copy of _PATH_STDPATH in the binary.


# 207678 05-May-2010 jilles

sh: Apply locale vars on builtins, recognize LC_MESSAGES as a locale var.

This allows doing things like LC_ALL=C some_builtin to run a builtin under a
different locale, just like is possible with external programs. The
immediate reason is that this allows making printf(1) a builtin without
breaking things like LC_NUMERIC=C printf '%f\n' 1.2

This change also affects special builtins, as even though the assignment is
persistent, the export is only to the builtin (unless the variable was
already exported).

Note: for this to work for builtins that also exist as external programs
such as /bin/test, the setlocale() call must be under #ifndef SHELL. The
shell will do the setlocale() calls which may not agree with the environment
variables.


# 205154 14-Mar-2010 jilles

sh: Do not abort on a redirection error on a compound command.

Redirection errors on subshells already did not abort the shell because
the redirection is executed in the subshell.

Other shells seem to agree that these redirection errors should not abort
the shell.

Also ensure that the redirections will be cleaned up properly in cases like
command eval '{ shift x; } 2>/dev/null'

Example:
{ echo bad; } </var/empty/x; echo good


# 205138 13-Mar-2010 jilles

sh: Do not abort on a redirection error if there is no command word.

Although simple commands without a command word (only assignments and/or
redirections) are much like special builtins, POSIX and most shells seem to
agree that redirection errors should not abort the shell in this case. Of
course, the assignments persist and assignment errors are fatal.

To get the old behaviour portably, use the ':' special builtin.
To get the new behaviour portably, given that there are no assignments, use
the 'true' regular builtin.


# 204802 06-Mar-2010 jilles

sh: Make sure to popredir() even if a function caused an error.


# 204801 06-Mar-2010 jilles

sh: Make sure to popredir() even if a special builtin caused an error.


# 204800 06-Mar-2010 jilles

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)


# 201431 03-Jan-2010 jilles

sh: Send the "not found" message for builtin <cmd> to redirected fd 2.


# 201366 01-Jan-2010 jilles

sh: Fix some bugs with backquoted builtins:
- correctly handle error output in $(builtin 2>&1), clarify out1/out2 vs
output/errout in the code
- treat all builtins as regular builtins so errors do not abort the shell
and variable assignments do not persist
- respect the caller's INTOFF

Some bugs still exist:
- expansion errors may still abort the shell
- some side effects of expansions and builtins persist


# 201343 31-Dec-2009 jilles

sh: Allow command -pv and command -pV (lookup using _PATH_STDPATH).


# 201283 30-Dec-2009 jilles

sh: Ensure funcnest is decremented if there was an error in the function.

This will be important when things like 'command eval f' will be possible.
Currently, the funcnest = 0 assignment in RESET (called when returning to
the top level after an error in interactive mode) is really sufficient.


# 201053 27-Dec-2009 jilles

sh: Various warning fixes (from WARNS=6 NO_WERROR=1):
- const
- initializations to silence -Wuninitialized (it was safe anyway)
- remove nested extern declarations
- rename "index" locals to "idx"


# 199953 29-Nov-2009 jilles

Fix some cases where file descriptors from redirections leak to programs.

- Redirecting fds that were not open before kept two copies of the
redirected file.
sh -c '{ :; } 7>/dev/null; fstat -p $$; true'
(both fd 7 and 10 remained open)
- File descriptors used to restore things after redirection were not
set close-on-exec, instead they were explicitly closed before executing
a program normally and before executing a shell procedure. The latter
must remain but the former is replaced by close-on-exec.
sh -c 'exec 7</; { exec fstat -p $$; } 7>/dev/null; true'
(fd 10 remained open)

The examples above are simpler than the testsuite because I do not want to
use fstat or procstat in the testsuite.


# 199660 22-Nov-2009 jilles

Fix various things about SIGINT handling:
* exception handlers are now run with interrupts disabled, which avoids
many race conditions
* fix some cases where SIGINT only aborts one command and continues the
script, in particular if a SIGINT causes an EINTR error which trumped the
interrupt.

Example:
sh -c 'echo < /some/fifo; echo This should not be printed'
The fifo should not have writers. When pressing ctrl+c to abort the open,
the shell used to continue with the next command.

Example:
sh -c '/bin/echo < /some/fifo; echo This should not be printed'
Similar. Note, however, that this particular case did not and does not work
in interactive mode with job control enabled.


# 199647 22-Nov-2009 jilles

sh: Ensure the same command input file is on top after executing a builtin.

This avoids weirdness when 'fc -e vi' or the like is done and there is a
syntax error in the file. Formerly an interactive shell tried to execute
stuff after the syntax error and exited.

This should also avoid similar issues with 'command eval' and 'command .'
when 'command' is implemented properly as in NetBSD sh.

Special builtins did not have this problem since errors in them cause the
shell to exit or to reset various state such as the current command input
file.


# 197820 06-Oct-2009 jilles

sh: Send the "xyz: not found" message to redirected fd 2.
This also fixes that trying to execute a non-regular file with a command
name without '/' returns 127 instead of 126.
The fix is rather simplistic: treat CMDUNKNOWN as if the command were found
as an external program. The resulting fork is a bit wasteful but executing
unknown commands should not be very frequent.

PR: bin/137659


# 196634 28-Aug-2009 jilles

sh: Fix crash with empty functions (f() { }) introduced in r196483

Empty pairs of braces are represented by a NULL node pointer, just like
empty lines at the top level.

Support for empty pairs of braces may be removed later. They make the code
more complex, have inconsistent behaviour (may or may not change $?), are
not specified by POSIX and are not allowed by some other shells like bash,
dash and ksh93.

Reported by: kan


# 196483 23-Aug-2009 jilles

sh: Fix crash when undefining or redefining a currently executing function.

Add a reference count to function definitions.
Memory may leak if multiple SIGINTs arrive in interactive mode,
this will be fixed later by changing SIGINT handling.

PR: bin/137640


# 194786 23-Jun-2009 jilles

Quote -x tracing output so it is unambiguous.

It is usually but not always suitable for re-input to the shell.

Approved by: ed (mentor) (implicit)


# 194774 23-Jun-2009 jilles

Do not fork for a subshell if it is the last thing this shell is doing
(EV_EXIT). The fork is still done as normal if any traps are active.

In many cases, the fork can be avoided even without this change by using {}
instead of (), but in practice many scripts use (), likely because the
syntax is simpler.

Example:
sh -c '(/bin/sleep 10)& sleep 1;ps -p $! -o comm='
Now prints "sleep" instead of "sh". $! is more useful this way.
Most shells (dash, bash, pdksh, ksh93, zsh) seem to print "sleep" for this.

Example:
sh -c '( ( ( (ps jT))))'
Now shows no waiting shell processes instead of four.
Most shells (dash, bash, pdksh, ksh93, zsh) seem to show zero or one.

PR: bin/74404
Approved by: ed (mentor) (implicit)


# 194765 23-Jun-2009 jilles

sh: Improve handling of setjmp/longjmp volatile:
- remove ineffective and unnecessary (void) &var; [1]
- remove some unnecessary volatile keywords
- add a necessary volatile keyword
- save the old handler before doing something that could use the saved
value

Submitted by: Christoph Mallon [1]
Approved by: ed (mentor)


# 194128 13-Jun-2009 jilles

Avoid leaving unnecessary waiting shells in many forms of sh -c COMMAND.

This change only affects strings passed to -c, when the -s
option is not used.

The approach is to check if there may be additional data
in the string after parsing each command. If there is none,
use the EV_EXIT flag so that a fork may be omitted in
specific cases.

If there are empty lines after the command, the check will
not see the end and forks will not be omitted. The same
thing seems to happen in bash.

Example:
sh -c 'ps lT'
No longer shows a shell process waiting for ps to finish.

PR: bin/113860
Reviewed by: stefanf
Approved by: ed (mentor)


# 194127 13-Jun-2009 jilles

Don't skip forking for an external command if any traps are active.

Example:
sh -c '(trap "echo trapped" EXIT; sleep 3)'
now correctly prints "trapped".

With this check, it is no longer necessary to check for -T
explicitly in that case.

This is a useful bugfix by itself and also important because I plan to
skip forking more often.

PR: bin/113860 (part of)
PR: bin/74404 (part of)
Reviewed by: stefanf
Approved by: ed (mentor)


# 193222 01-Jun-2009 rse

correctly test for __GNUC__ macro (non-GCC compilers do not have it defined at all)


# 193169 31-May-2009 stefanf

Fix the eval command in combination with set -e. Before this change the shell
would always terminate if eval returned with a non-zero exit status regardless
if the status was actually tested. Unfortunately a new file-scope variable
is needed, the alternative would only be to add a new parameter to all
built-ins.

PR: 134881


# 190698 04-Apr-2009 stefanf

Don't let trailing empty lines overwrite the result of the last command with 0.
This affects the built-ins eval, fc, and trap and also the string passed to sh
with the -c option.

Submitted by: Jilles Tjoelker


# 185231 23-Nov-2008 stefanf

Fix $? at the first command of a function. The previous exit status was saved
twice and thus lost.


# 181017 30-Jul-2008 stefanf

Pass the correct flags to expandarg() for NFROMFD and NTOFD. This fixes a
segmentation fault when the argument expands to an empty string.

Reported by: simon
MFC after: 3 weeks


# 172440 04-Oct-2007 stefanf

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)


# 159633 15-Jun-2006 stefanf

Merge NetBSD's revision 1.86: Don't crash on "<cmd> | { }".


# 159632 15-Jun-2006 stefanf

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


# 157601 09-Apr-2006 stefanf

Implement some of the differences between special built-ins and other builtins
demanded by POSIX.
- A redirection error is only fatal (meaning the execution of a shell script is
terminated) for special built-ins. Previously it was fatal for all shell
builtins, causing problems like the one reported in PR 88845.
- Variable assignments remain in effect for special built-ins.
- Option or operand errors are only fatal for special built-ins.
This change also makes errors from 'fc' non-fatal (I could not find any reasons
for this behaviour).

Somewhat independently from the above down-grade the error handling in the
shift built-in if the operand is bigger than $# from an error() call (which is
now fatal) to a return 1. I'm not sure if this should be considered a POSIX
"operand error", however this change is needed for now as we trigger that error
while building libncurses. Comparing with other shells, zsh does the same as
our sh before this change (write a diagnostic, return 1), bash behaves as our
sh after this commit (no diagnostic, return 1) and ksh93 and NetBSD's sh treat
it as a fatal error.


# 155301 04-Feb-2006 schweikh

Remove some white space at EOL.


# 153091 04-Dec-2005 stefanf

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.


# 151854 29-Oct-2005 stefanf

Forced commit to note the patch for the previous commit was

Submitted by: rodrigc


# 151810 28-Oct-2005 stefanf

Add the POSIX options -v and -V to the 'command' builtin. Both describe the
type of their argument, if it is a shell function, an alias, a builtin, etc.
-V is more verbose than -v.

PR: 77259, 84539


# 149933 10-Sep-2005 stefanf

Pass the EV_TESTED flag to evalloop() and evalfor(). This fixes unwanted
termination with set -e if a command fails in a loop body inside a function
with an explicitely tested exit status, eg

f() {
for i in 1 2 3; do
false
done
}
f || true

Briefly reviewed by: cracauer


# 149932 10-Sep-2005 stefanf

Pass the EV_TESTED flag to the left operand of NSEMI nodes. This fixes
two cases of unwanted termination with set -e:

* if-commands containing several commands separated by semicolons, eg

if false; false; then [...]

* functions with an explicitely tested exit status that contain a failing
command which is not the last one, eg

f() {
false
false
}
f || true

PR: 77067, 85267
Briefly reviewed by: cracauer


# 149927 10-Sep-2005 stefanf

Exit the shell if a pipeline that is not preceded by ! fails and set -e is
active. Use a separate flag to avoid adding another condition to the
if-statement at the end of evaltree().

Briefly reviewed by: cracauer


# 149802 05-Sep-2005 stefanf

Print pointers with %p rather than casting them to long.


# 127958 06-Apr-2004 markm

Remove clause 3 from the UCB licenses.

OK'ed by: imp, core


# 125153 28-Jan-2004 cracauer

The PR diff I committed recently had one bug noticed by
Joe Marcus Clarke <marcus@FreeBSD.ORG>, subshells could lose a
non-zero exit status.

This commit is Joe's proposed patch. Thanks!

I verified that the problem Joe found is fixed and I ran a full world
with this patch.

I don't plan to ever commit language patches to /bin/sh again. It is
a minefield too big to navigate without a full-time committment, which
I am not willing to do on our /bin/sh.

Under normal circumstances I would recommend using NetBSD's sh which
has a lot of language fixes (like the ones what these patches were
about) but unfortunately they had implemented broken signal behaviour
for shellscript containing interactive programs. Similar issues apply
to pdksh which is OpenBSD's sh.

From my perspective bash2 is the only really working bourne sh out
there and that one is GPLed. Oh well.


# 124780 21-Jan-2004 des

Replace home-grown dup2() implementation with actual dup2() calls. This
should slightly reduce the number of system calls in critical portions of
the shell, and select a more efficient path through the fdalloc code.

Reviewed by: bde


# 123996 30-Dec-2003 maxim

o Spell 'diretories' correctly.

PR: misc/60730
Submitted by: Eugene Grosbein
MFC after: 3 days


# 123921 28-Dec-2003 cracauer

PR 28852

sh -e behaviour was incorrect when && and || statements where used in
"if" clauses.

This is the patch submitted by MORI Kouji <mori@tri.asanuma.co.jp>.

It fixes the issue at hand, but sh fixes like this are super-hard to
verify that they don't break anything else. I ran some of my old test
cases and a few big GNU configure scripts that detected mistakes
before, with the previous sh, patched sh and bash. No differences in
behaviour found. MFC recommended after longer than usual time.

Compiles on i386 and sledge.


# 109627 21-Jan-2003 tjr

Make this compile with DEBUG defined now that WARNS=0 has been removed
from the Makefile:
- Print pointers with %p instead of %x.
- Include missing headers to get prototypes.

Noticed by: benno


# 102576 29-Aug-2002 keramida

Add <stdlib.h> to get a prototype for exit().

Reviewed by: tjr


# 100663 25-Jul-2002 tjr

Set opterr to zero to avoid duplicate warnings from getopt(3) for unknown
options.


# 100437 21-Jul-2002 tjr

Implement the P1003.2 `command' builtin command, which is used to suppress
shell function and alias lookup. The -p option has been implemented, the
UPE -v and -V options have not. The old `command' command has been renamed
to `builtin'.


# 99110 30-Jun-2002 obrien

Consistently use FBSDID


# 96922 19-May-2002 tjr

Implement the -C (-o noclobber) option, which prevents existing regular
files from being overwritten by shell redirection.


# 90111 02-Feb-2002 imp

o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
they already are.
o Change
int
foo() {
...
to
int
foo(void)
{
...


# 77557 31-May-2001 gad

Fix how /bin/sh handles 'for' and 'case' statements when it is called to do
errexit (-e) processing. This solves a problem where 'make clean' would
fail with an unspecified error in certain automake-generated makefiles.

Reviewed by: no objections from -hackers...
MFC after: 2 weeks


# 66612 03-Oct-2000 brian

Implement the <> redirection operator.


# 60592 15-May-2000 cracauer

Fix environment passung to eval'ed commands.

PR: bin/6577
Submitted by: Anatoly Vorobey <mellon@pobox.com>
Approved by: silence amoung other sh experts


# 54884 20-Dec-1999 cracauer

Fix command hash handling on
PATH=... command

Noted by and fix works for Marcel Moolenaar <marcel@scc.nl>


# 53891 29-Nov-1999 cracauer

Include strerror(errno) in error messages after failed system calls.
Fix a warning.


# 53282 17-Nov-1999 cracauer

The pipleline problem introduced in version 1.22 wasn't fully fixed in
1.23. This revision should work for long pipes both in
here-documents/backquote and in normal cases.

Fix works for jmz, bde.


# 52972 07-Nov-1999 steve

Correct logic from previous commit - middle processes in long pipes
don't have their stdin closed indisciminantly.

Reviewed by: markm


# 52900 05-Nov-1999 cracauer

When a backquote command inside a here-document had a pipe with more
than two processes (got that? :-), the stdin fd of the middle
processes that has just been set up was accidetially closed. Don't do
this.

PR: bin/14527


# 52526 26-Oct-1999 cracauer

Fix ';' command when used with -e flag.

PR: bin/14509


# 50471 27-Aug-1999 peter

$Id$ -> $FreeBSD$


# 48896 19-Jul-1999 sheldonh

Fix handling of the cd command inside evaluations. It was changing PWD,
which it should not do.

PR: 12578
Reported by: Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
Submitted by: Niall Smart <niall@pobox.com>


# 46684 08-May-1999 kris

Various spelling/formatting changes.

Submitted by: Philippe Charnier <charnier@xp11.frmug.org>


# 45916 21-Apr-1999 cracauer

Next approach to make loops in interactive interruptable.

PR: bin/9173


# 45266 03-Apr-1999 cracauer

In interactive shells, break loops to the topmost level when a child
is killed by a signal.

(In non-interactive shells - that means a shellscript - the shell just
exits, this was already working)

PR: bin/9173


# 45221 01-Apr-1999 cracauer

The immediate execution of traps I introduced in September 1998 (to
make /etc/rc interruptible in cases when programs hang with blocked
signals) isn't standard enough.

It is now switched off by default and a new switch -T enables it.

You should update /etc/rc to the version I'm about to commit in a few
minutes to keep it interruptible.


# 36150 18-May-1998 charnier

Add rcsid. Spelling.


# 35675 04-May-1998 cracauer

When calling a shell function, remember whether exit status is tested.
This is needed for the '-e' option. See the PR for more details.
PR: 6047
Reviewed by: PR submitter, silence on review request.


# 25905 18-May-1997 steve

Use the __unused attribute where warranted.


# 25222 28-Apr-1997 steve

Nuke register keyword usage and #if -> #ifdef.

Obtained from: NetBSD


# 22988 22-Feb-1997 peter

Revert $FreeBSD$ to $Id$


# 21673 14-Jan-1997 jkh

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 20425 14-Dec-1996 steve

Merge in NetBSD mods and -Wall cleaning.

Obtained from: NetBSD, me


# 19683 12-Nov-1996 peter

Back out rev 1.7 which was to fix PR#1206 (to be reopened).

This patch causes too many side effects, one of which bites hard is
when interrupting a 'make fetch' in the ports tree (PR#1990).
This whole area is a real can of worms....

This most definately should go into 2.2

Reviewed by: steve, bde


# 19084 22-Oct-1996 steve

Close PR# 1206. sh(1) now ignores SIGINT and SIGQUIT
when a child is forked and the -c commandline switch
has been specified.

Reviewed by: joerg


# 18754 06-Oct-1996 steve

Fix a problem with sh that conflicts with the -e
flag text in the man page. Now this will work
correctly:

/bin/sh -ec 'false && true; echo hi'

Obtained from: VaX#n8 <vax@linkdead.paranoia.com>


# 17987 01-Sep-1996 peter

Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is a
merge of parallel duplicate work by Steve Price and myself. :-]

There are some changes to the build that are my fault... mkinit.c was
trying (poorly) to duplicate some of the work that make(1) is designed to
do. The Makefile hackery is my fault too, the depend list was incomplete
because of some explicit OBJS+= entries, so mkdep wasn't picking up their
source file #includes.

This closes a pile of /bin/sh PR's, but not all of them..

Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter


# 10917 20-Sep-1995 dg

Don't dereference a NULL pointer in the case of a null pipe.
e.g.:
ls |> foo.out

sh now behaves the same as it does under SunOS 4.x for this case.


# 8855 29-May-1995 rgrimes

Remove trailing whitespace.

Reviewed by: phk


# 3044 24-Sep-1994 dg

Added $Id$


# 1557 26-May-1994 rgrimes

This commit was generated by cvs2svn to compensate for changes in r1556,
which included commits to RCS files with non-trunk default branches.


# 1556 26-May-1994 rgrimes

BSD 4.4 Lite bin Sources