Commit Graph

679 Commits

Author SHA1 Message Date
lukem 1e840c4d40 Ensure that $TERM is set in the real environment before calling el_init(3)
when executing "set -o (emacs|vi)".   Fixes [bin/23175] from me.
2003-10-19 01:55:05 +00:00
lukem a9d371700c improve MAKEVERBOSE message for HOST_LINKed tools 2003-10-19 00:43:02 +00:00
lukem 29e7d09b65 Support MAKEVERBOSE (XXX: mksyntax is noisy when MAKEVERBOSE=0).
Use DPSRCS appropriately.
2003-10-19 00:35:26 +00:00
lukem 51b9502fb1 Link the host tools against tools/compat -lnbcompat since someone decided to
use strlcpy() and snprintf() in the host tools...

Should fix part of [toolchain/22504], and build problems on other
platforms that don't have strlcpy() or snprintf()...
2003-10-18 07:58:35 +00:00
dsl b17e1b5c12 Fix 'set "*" b; case "* b" in "$@") ...' and 'set "*"; case 1 in "${#1}") ...'
Which got broken by the previous fix.
2003-09-22 12:17:24 +00:00
jmmv 4c79e7620f Drop equal signs from rule definitions; they cause problems with "bison -y". 2003-09-17 17:33:36 +00:00
christos 4dcb41ae2c PR/22640: Paul Jarc: sh mishandles positional parameters in case. Fixed
from FreeBSD PR 56147.
2003-09-17 16:01:19 +00:00
jmmv 0ec085e737 Add 'trace' to CLEANFILES, generated when debug is enabled. 2003-09-14 12:11:10 +00:00
jmmv af90286087 Fix crash when DEBUG=2, by opening the log file ASAP. Reviewed by simonb@. 2003-09-14 12:09:29 +00:00
jmmv aba1ca99ae Include strings.h, needed for index's prototype. 2003-08-26 18:14:24 +00:00
jmmv 6d82007582 Use '\0' instead of NULL in two checks (we are not checking for a pointer
value).  While here, add a missing whitespace.
2003-08-26 18:13:25 +00:00
jmmv 5199a59afa s/FD_SETFD/F_SETFD/ 2003-08-26 18:12:33 +00:00
jmmv 534b18e585 Move an assignment that was using a variable out of scope to fix a build
problem on !NetBSD.
2003-08-25 20:08:12 +00:00
itojun 59a105b48a remove \r (agc, are you using MS-DOS?) 2003-08-22 14:21:12 +00:00
agc 3538d2653b Move 4 more files from UCB 4 clause to 3 clause licence.
Thanks to Julio Merino for pointing them out.
2003-08-22 11:22:23 +00:00
christos e9a8269bb0 remove clause 3 2003-08-21 17:57:53 +00:00
agc b5b2954259 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22249, verified by myself.
2003-08-07 09:05:01 +00:00
itojun a69cd45b93 use bounded string op 2003-07-13 08:31:13 +00:00
wiz 5127f8f2c1 Quote some punctuation. 2003-06-27 09:11:12 +00:00
dsl a9fc176e82 Don't close any script files if vfork is set.
If a fork() is done later in order to feed a 'here' document into a pipe
then it is possible that one end of the pipe might get closed.
2003-05-15 13:26:45 +00:00
dsl 49e6852272 Fix problems with parallel makes. 2003-05-15 10:13:36 +00:00
dsl 6285ef062c Use echo instead of cat to add prologue to builtins.[ch]
Under some circumstances the headers got overwritten.
2003-05-15 10:11:01 +00:00
christos dd61e68e1f Use ${HOST_SH} 2003-05-08 13:03:19 +00:00
wiz f0b76593e4 Drop trailing space. 2003-05-06 08:33:08 +00:00
dsl 534ba36ad4 Recognise octal and hexadecimal constants in expressions.
- as required by SUSv3
2003-05-06 08:10:42 +00:00
gmcgarry 5e5ffccb2b ANSIify. 2003-05-04 06:36:50 +00:00
gmcgarry f8d2e9e189 Add new builtin 'inputrc' which allows keybindings to be redefined
for the current shell.  From Arne H Juul in PR#10097.
2003-05-04 01:05:24 +00:00
gmcgarry 62bb6faae3 Expand documentation of emacs and vi modes. From
Jeremy C. Reed in PR#14578.
2003-05-02 09:00:14 +00:00
itojun e6a384fc32 %d is 12 chars, not 10 chars. hinted by deraadt 2003-04-15 07:40:56 +00:00
zuntum 1a2ec1a713 add missing parenthesis 2003-04-12 16:39:19 +00:00
kristerw 7fee304b15 Change "if" to "if and only if" per discussion in PR 20794. 2003-03-22 11:37:49 +00:00
lukem c61fa8df18 If building as a CRUNCHEDPROG, use "lex -L" and "yacc -l" to suppress #line
generation.  This may solve [bin/20637].
2003-03-10 17:58:21 +00:00
wiz 990562bfef .Nm does not need a dummy argument ("") before punctuation or
for correct formatting of the SYNOPSIS any longer.
2003-02-25 10:34:36 +00:00
wiz 4cc7cdbc5c New sentence, new line; bump date for last change. 2003-02-12 18:58:50 +00:00
gmcgarry 8a0ced42ec Introduce LANG environment variable and Xref to nls(7).
Comment out the statement: "We expect POSIX conformance
by the time 4.4BSD is released."
2003-02-12 02:55:14 +00:00
dsl 51d94f2156 Fix bin/20185 - builtin called from function of same name mustn't be hashed.
Make 'hash' only report utilities that are not builtins (posix), the
non-posix 'hash -v' will report everything.
(agreed by christos)
2003-02-04 08:51:30 +00:00
dsl 0871280204 Parse end of line comments correctly
(approved by christos)
2003-02-02 21:10:45 +00:00
christos 66b9125762 - use FD_CLOEXEC properly
- move ttyfd to a high fd
suggested by Tim Robbins at FreeBSD.
2003-01-27 12:54:08 +00:00
wiz 6ce643e53c Fix indentation of continuation of first line in SYNOPSIS. 2003-01-23 18:32:07 +00:00
agc 53ed48f326 Make this build on platforms where size_t != int, i.e. sparc, arm, ppc, ... 2003-01-23 14:58:07 +00:00
rafal 0923f4be26 Make this build again. 2003-01-23 03:33:16 +00:00
wiz e254f6a849 More markup, more commas, less typos. 2003-01-22 22:05:45 +00:00
dsl e314f958bd Support command -p, -v and -V as posix
Stop temporary PATH assigments messing up hash table
Fix sh -c -e "echo $0 $*" -a x (as posix)
(agreed by christos)
2003-01-22 20:36:03 +00:00
kleink b3df6303a9 Rename `sigset' locals to avoid symbol shadowing warning. 2003-01-16 09:38:37 +00:00
christos 51457e8842 Make sure that UPEOF is compared to the right type on the left hand
side. Sometimes it was compared to int, which was -1 on EOF, and on
unsigned char machines UPEOF was (unsigned char)-1. This worked
by chance because isalpha((unsigned char)-1) returns false usually,
but it does not when the locale is invalid!
2003-01-12 20:26:53 +00:00
christos a17201f05e allow this to be compiled with unsigned-chars. 2003-01-09 13:57:26 +00:00
wiz 617b132aac Spell output with two ts. 2003-01-04 23:43:02 +00:00
uebayasi 80a4544dcd trap '' SIGINT -> trap '' INT. 2002-12-28 05:08:27 +00:00
kleink 9273e5b038 Another it's -> its. 2002-12-19 18:04:41 +00:00
uebayasi 60ad876a43 `` [n1]>&n2 Duplicate standard output (or n1) _TO_ n2.'' 2002-12-12 11:50:40 +00:00
christos aa0e549885 PR/19453: Christopher Richards: Call setlocale() in /bin/sh 2002-12-11 19:12:18 +00:00
agc 1aafd1a470 Include <stdio.h> to get the prototype for sprintf(3) - macppc needs this. 2002-11-25 21:55:58 +00:00
agc ea1d615943 Make this compile on some of the more esoteric architectures (e.g. those
which are not i386)
2002-11-25 12:13:03 +00:00
christos c02b3bbdf4 Fixes from David Laight:
- ansification
- format of output of jobs command (etc)
- job identiers %+, %- etc
- $? and $(...)
- correct quoting of output of set, export -p and readonly -p
- differentiation between nornal and 'posix special' builtins
- correct behaviour (posix) for errors on builtins and special builtins
- builtin printf and kill
- set -o debug (if compiled with DEBUG)
- cd src obj (as ksh - too useful to do without)
- unset -e name, remove non-readonly variable from export list.
  (so I could unset -e PS1 before running the test shell...)
2002-11-24 22:35:38 +00:00
wrstuden 5b0a9938fd Use signed char to replace int8_t, not just char. Should fix macppc
cross-build problems introduced in rev 1.59.

Pointed out by Valeriy E. Ushakov uwe at ptc dot spbu dot ru on
tech-toolchain.
2002-10-31 17:14:46 +00:00
christos dde7426849 From David Laight
> The wrong process is aborting when variable assignment fails
> in the vfork path.  So the following command fails to execute
> the second echo (shown here with the correct output).
>
> $ (readonly r; r= /bin/echo a; echo b)
> r: is read only
> b
>
> fix: defer the mklocal() to the child shell.
2002-10-23 19:46:34 +00:00
christos f3dfd6e686 From David Laight:
> Also 'jobs' fails in a non-interactive shell.
> In showjobs(), the code that puts the process back into its
> own process group should only be run if the shell is actually
> doing job control - eg if 'mflag' is set.
2002-10-23 19:46:06 +00:00
christos 6166cc6e93 Fix interrupt problam from David Laight
$ /fred # non existant command
$ ^C # stops working

He says:
    Ok the extra INTOFF is the one in exverror().
    In almost all cases this doesn't matter because the longjmp()s
    all end up in main() and the FORCEINTON call sorts it out
    for the next command.
    (There are a significant number of INTON/OFF mismatches through
    the error paths...)

    In any case the above failure can be 'fixed' by changing 2 (I think
    they are both needed) INTON calls to FORCEINTON within evalcommand.
    The following patch seems to work:

We should really look in the code and fix the INTON->INTOFF pairs.
2002-10-23 13:25:24 +00:00
lukem e490a5c798 don't compile in `-h' as a synonym for the command that the argument is for.
this fix is hokey, but works as well as the previous solution for -j.
2002-10-15 04:15:58 +00:00
christos 1ce87c4b29 - it is wrong to put inton/intoff arount ckmalloc(), because the code
around it is the one that does this.
- whitespace fixes.
2002-10-07 14:26:49 +00:00
christos 202746f803 explain what's breaking with alignments > 16, but no fix yet. 2002-10-07 14:26:08 +00:00
christos b9d3050e20 Rename ALIGN to SHELL_ALIGN and simplify macro so that it does not have side
effects, and add double to it, so that it aligns doubles correctly too. This
is just a workaround to fix the sparc64 problem where ALIGN() is now defined
in some include file to be 16 instead of 8. Thanks to martin for debugging this.
2002-10-04 13:15:51 +00:00
wiz 1da66f1f4c filesystem -> file system, automaticly -> automatically. 2002-10-02 10:01:46 +00:00
wiz 2e6e2165c0 Use more mdoc, particularly to get rid of some \*[Lt] and \*[Gt]. 2002-10-01 15:06:31 +00:00
mycroft 6092f7d52b Revert the previous for now. This is truly gross. 2002-09-28 03:15:43 +00:00
mycroft 7973b7a0ac Remove the duplicate setpgid() in forkparent(). The real bug was freeing the
job structure in the child and referencing freed memory.
2002-09-28 03:08:00 +00:00
christos 4783843fdc Revert previous change. No need to save rootshell. It is only affecting
the non-vfork case. Having said that, it would be nice if pipelines of
simple commands were vforked too. Right now they are not.
Explain that setpgid() might fail because we are doing it both in the
parent and the child case, because we don't know which one will come
first.
Suspending a pipeline prints %1 Suspended n times where n is the number
of processes, but that was there before. It is easy to fix, but I'll
leave the code alone for now.
2002-09-28 01:25:01 +00:00
christos 6f48233483 Deal with rootshell not being maintained correctly in the vfork() case.
Propagate isroot, throughout the eval process and maintain it properly.
Fixes sleep 10 | cat^C not exiting because sleep and cat ended up in
their own process groups, because wasroot was always true in the children.
2002-09-27 22:56:24 +00:00
mycroft d84d36165d Clean up INTOFF/INTON usage a little -- none of fork{shell,parent,child}()
screw with them now, only their callers.
2002-09-27 21:32:24 +00:00
christos ad1e7bca30 off by one in nprocs. 2002-09-27 21:04:08 +00:00
christos 35975338b0 Put back charles' fixes from -r1.60 2002-09-27 20:24:36 +00:00
christos edcb454443 VFork()ing shell: From elric@netbsd.org:
Plus my changes:
	- walking process group fix in foregrounding a job.
	- reset of process group in parent shell if interrupted before the wait.
	- move INTON lower in the dowait so that the job structure is
	  consistent.
	- error check all setpgid(), tcsetpgrp() calls.
	- eliminate unneeded strpgid() call.
	- check that we don't belong in the process group before we try to
	  set it.
2002-09-27 18:56:50 +00:00
mycroft 2aa6ebd4ed In evalpipe(), move the INTOFF after the waitforjob(), to prevent possible
race conditions -- now we always synchronously wait for the job to finish.
In evalcommand(), add the same INTOFF/INTON locking as evalpipe(), to prevent
leaving internal state inconsistent, and also to insure that we synchronously
wait for the job.
2002-09-27 17:37:12 +00:00
christos 6438e7dcdc no SYSV for eagain, enable EMFILE 2002-09-27 16:56:15 +00:00
wiz 14dfaa4b03 New policy: New sentences start on a new line.
Patches by Robert Elz <kre at munnari oz au>, with minimal changes by me.
2002-09-25 15:18:36 +00:00
thorpej e41b1aa4a2 Use "unsigned char" and "char" instead of "u_int8_t" and "int8_t"
for TARGET_CHAR when building mksyntax.  This isn't perfect, but
it lets the host tool work on non-BSD systems without completely
redoing how sh is built.
2002-09-15 00:19:22 +00:00
lukem 146a774973 Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path (etc). 2002-08-19 09:56:00 +00:00
christos 82886e162e deal with char c; c != -129 warning. Hi jason! 2002-05-31 16:18:48 +00:00
wiz 10610e5a31 __STDC__ is always defined on NetBSD. 2002-05-25 23:12:16 +00:00
wiz 0b398b282c __STDC__ is always defined on NetBSD, so remove #ifdef __STDC__ (and
unnecessary #else cases).
2002-05-25 23:09:06 +00:00
bjh21 84c006d0f8 The printf builtin has been "temporarily" disabled for eight years. Remove
its directory from .PATH to avoid confusion.
2002-05-15 20:45:17 +00:00
bjh21 6f786375c4 Implement sh -a (allexport). Code (all two lines of it) from FreeBSD
(FreeBSD var.c 1.13, sh.1 1.27).
2002-05-15 19:43:29 +00:00
christos f629aa28d9 implement noclobber. From Ben Harris, with minor tweaks from me. Two
unimplemented comments to go. Go Ben!
2002-05-15 16:33:35 +00:00
christos eac955176d Implement unset variable error messages from Ben Harris. 2002-05-15 14:59:21 +00:00
christos de525ac6ca Try harder to find a tty. 2002-04-10 15:52:07 +00:00
thorpej 3ea17f6cff Move the declaration of digit[] into the #ifdef'd code block that
uses it.  Prevents a warning from gcc 3.2.
2002-04-09 00:52:05 +00:00
christos e6ab6d48dc PR/16174: Matthias Buelow: Job control fails on jobs that fd == 2 does not
point to a tty.

Unfortunately the shell assumed that it could do all process group
handling ioctls to fd=2, but this is not correct. Jobs that redirected
fd=2 would be unable to perform the ioctls and silently fail since
the error reporting channel is fd=2... Instead open /dev/tty set
it to close on exec, and use that instead (like all other shells
do). We don't handle the case where the OS does not provide FD_CLOEXEC
or FIOCLEX, because I am lazy.

While I am there:
- Simplify the code by defining functions for tc{g,s}pgrp when OLD_TTY_DRIVER
  is defined.
- make sure that 'sh &' works by stopping itself. Don't kill the shell's
  process group, kill the shell itself.
2002-04-03 14:30:44 +00:00
christos c910c75b83 PR/16010: Andreas Gustafsson: wait is not interruptible. 2002-03-22 19:50:42 +00:00
simonb 668ba50fa3 In forkshell() don't free the current job. Fixes problem with previous
commit where pipeline commands didn't inherit the correct process group.
Reviewed by Christos.

Change a trace format string arg to use %p instead of %x and a long cast.
2002-03-12 03:45:02 +00:00
christos bac9369a06 PR/15877: Ed Ravin: make sure that we cleanup enough of the job structure,
in jobfree() so that we don't fail when we use a malloc where free() trashes
freed memory.
2002-03-12 00:44:16 +00:00
christos ccbeeb7cba get rid of sp completely, we were free-ing a bogus pointer; found by simonb. 2002-03-12 00:14:31 +00:00
lukem b799ed2973 first variable argument to "read" is not optional 2002-02-24 21:41:52 +00:00
christos 8b449b1ee8 enami convinced me that it is a good idea to use the first word of
the allocated area.
2002-02-20 21:42:35 +00:00
christos 06ea4006cb PR/11542: Back-out previous change that caused
set -e
for x in a; do
    BAR="foo"
    false && echo true
    echo mumble
done

not to echo mumble...
2002-02-14 21:51:41 +00:00
christos 6c02afd8c4 Since we should be able to handle nested double quotes, don't use
the syntax maps to determine the beginning and end quotes (kill
CENDQUOTE).  Handle single quotes opening and closing via checking
the current syntax map. Keep a bitmap of doublequote state one bit
per variable nesting level.  For the first 32 nested double quotes,
we don't need any additional memory, but for more we allocate
dynamically.
2002-02-12 20:32:35 +00:00
ross 79f9ab6771 back this directory up a day, systems won't even boot (rc.subr splodes)
suggested back-to-the-drawing-board test: $ echo "${PWD:-notlikely}"
2002-02-12 06:39:10 +00:00
christos f63e9a1ed6 PR/15579: Alan Barrett: }'s inside variable specs were taken into account
even if quoted:
    foo=${foo:-"'{}'"}; echo $foo
would display '{'} instead of '{}'.
2002-02-11 18:57:19 +00:00
christos 39d26b8867 Add a commented out -DDEBUG in CPPFLAGS. 2002-02-11 18:55:10 +00:00
christos 4398551708 Fix off by one in the display of var trees. 2002-02-11 18:54:30 +00:00
ross dc5571b22e Generate <>& symbolically. I'm avoiding .../dist/... directories for now. 2002-02-08 01:21:55 +00:00
lukem 9c2af9970a .ifdef SMALLPROG, -DSMALL 2002-02-07 06:25:07 +00:00
wiz 5739c48f68 Punctuation nits, drop unnecessary .Pps, sort sections. 2001-12-20 20:07:40 +00:00
wiz 9f4702dcef Punctuation nit. 2001-12-20 20:06:45 +00:00
wiz 3ebcdc5e43 Whitespace nits. 2001-12-20 19:31:48 +00:00
he ed00fe0aee Plug a memory leak when setting PWD -- don't mark the variable with
VTEXTFIXED because the value is dynamically allocated.  Fix from
Tor Egge, FreeBSD PR#31533.
2001-11-14 18:04:36 +00:00
lukem 678a800f83 change from WARNS?=1 to WARNS?=2 for bin/ 2001-11-03 13:40:30 +00:00
christos 0598afe4d0 Fix switch alias handling. Inspired from FreeBSD, but corrected to handle
alias expansion inside the switch as appropriate. This is achieved by a
flag noalias which is turned on and off in as we parse. In the following
example [1] and [0] indicate the value of noalias.

[0] case <expr> in
[1] <lit> ) [0] <expr> ;;
[1] <lit> ) [0] <expr> ;;
...
[1] esac [0]

FreeBSD does:

[0] case <expr> in [1]
<lit> ) <expr> ;;
<lit> )  <expr> ;;
...
esac [0]

This handles the following shell script:

alias a=ls

case $1 in
a)	echo a;
	a;;
f)	echo f;;
*)	echo default;;
esac
2001-11-02 23:49:14 +00:00
wiz 4c99916337 va_{start,end} audit:
Make sure that each va_start has one and only one matching va_end,
especially in error cases.
If the va_list is used multiple times, do multiple va_starts/va_ends.
If a function gets va_list as argument, don't let it use va_end (since
it's the callers responsibility).

Improved by comments from enami and christos -- thanks!

Heimdal/krb4/KAME changes already fed back, rest to follow.

Inspired by, but not not based on, OpenBSD.
2001-09-24 13:22:25 +00:00
itojun 31952d578f make sure we do not truncate arith expresssion > 10 digits.
freebsd bin/sh/expand.c revision 1.15.  NetBSD PR 13943.
2001-09-19 06:38:19 +00:00
wiz 456dff6cb8 Spell 'occurred' with two 'r's. 2001-09-16 16:34:23 +00:00
assar 50ed29b359 (waitproc): handle jp == NULL, it happens 2001-09-13 21:33:05 +00:00
christos a7560f06ec Don't wait with UNTRACED for jobs that have not been started with job control
(i.e. processes started from shell scripts). Fixes problem where kill -STOP'ing
a subprocess of a shell script would cause the shell to proceed to the next
command.
2001-09-10 15:47:03 +00:00
lukem c0b18597d8 fix grammar 2001-06-13 08:48:06 +00:00
wiz 40ac848024 Fix various misspellings of compatible/compatibility. 2001-06-11 01:50:48 +00:00
bjh21 45a6b58c3e Use ${MACHINE_CPU} == "arm" to test for ARMishness. 2001-04-18 17:35:36 +00:00
christos ea8e5cf90b PR/12533: Koji Mori: eval gets misparsed when it has a trailing semi-colon. 2001-04-03 15:00:11 +00:00
wiz 242b959069 Don't xref set(1) and case(1), since they are builtins and we don't
have separate man pages for them.
Xref passwd 5 instead of 4, environ 7 instead of 5, and comment out xref
to profile(4), which we don't have.
Improve markup of SYNOPSIS.
Some whitespace fixes while I'm here.
2001-04-03 10:56:03 +00:00
toddpw e08886d505 Correct {list;} example and fix formatting/typo in the operator lists. 2001-04-01 02:15:45 +00:00
mycroft 59771e308b Globbing should match broken symlinks. stat()->lstat() to fix this. 2001-03-30 17:45:00 +00:00
wulf 8d23cb0373 Extended functionality of the trap builtin, which now closely follows
POSIX recommendations.

	- trap now accepts signal names and signal numbers
	  e.g. INT, SIGINT, 2
	- added option -l that outputs a list of valid signals
	- added signal EXIT to list of valid signals
	- a `-' in the action part will reset specified signal to their
	  default behaviour
	- changed standard output format to make it suitable as an input
	  to another shell that achieves the same trapping results
2001-03-18 04:04:23 +00:00
wiz 8d35854b5d Fix command name in error message for 'sh nonexistingfile'. 2001-02-26 13:06:43 +00:00
christos 3380980447 remove redundant declarations and nexted externs. 2001-02-04 19:52:06 +00:00
christos 80d86b9e7c remove redundant declaration of yyparse, and move code to the bottom of
the file.
2001-02-04 19:51:43 +00:00
lukem 10fc746e6d if HAVE_VASPRINTF (set ifdef BSD4_4), use vasprintf() instead of homegrown
code in doformat().  results in slightly smaller /bin/sh.  idea suggested by
Witold J. Wnuk <witek@pd37.warszawa.sdi.tpnet.pl>, approved by christos.
2001-01-07 23:39:07 +00:00
lukem dd7296f47a support %ll (as synonym for %q) in doformat(), since my changes to %q -> %ll
broke this :/
problem reported in private email by Witold J. Wnuk.
<witek@pd37.warszawa.sdi.tpnet.pl>.
2001-01-07 22:19:53 +00:00
lukem f819878ce7 use more standard %ll_ in favour of %q_ 2001-01-04 15:39:50 +00:00
bjh21 c9ee8d3362 arm26 has unsigned chars too. 2000-12-29 16:30:31 +00:00
cgd 84d782a52f __CONCAT does token pasting, not string concatnation. if something like:
__CONCAT("PATH=",_PATH_STDPATH);
actually works to concantate strings, it's because the preprocessor expands
it into "PATH=""whatever _PATH_STDPATH is" as separate strings, and then
ANSI string concatenation is performed on that.  It's more straightforward
to just use ANSI string concatenation directly, and newer GCCs complain
(rightly) about mis-use of token pasting.
2000-12-20 00:15:10 +00:00
christos 1d9dab3e95 error message cleanup:
- don't print the builtin name twice
    - explain why things fail
    - no extra newline
2000-11-22 19:20:31 +00:00
christos 212627911f fix typo. 2000-11-20 17:48:05 +00:00
christos fb16d6d0ec Add an example on how to use getopts, stolen from the getopt manual page :-) 2000-11-20 16:59:56 +00:00
mycroft 3112db7eb8 Call el_source() to use .editrc. 2000-11-06 04:21:14 +00:00
christos 8e2797bc1e PR/11283: Hubert Feyrer: random memory corruption executing commands:
Fix from FreeBSD:

    growstackblock() sometimes relocates a stack_block considered empty
    without properly relocating stack marks referencing that block.
    The first call to popstackmark() with the unrelocated stack mark
    as argument then causes sh to abort.

    Relocating the relevant stack marks seems to solve this problem.

    The patch changes the semantics of popstackmark() somewhat.  It can
    only be called once after a call to setstackmark(), thus cmdloop() in
    main.c needs an extra call to setstackmark().
2000-11-01 19:56:01 +00:00
christos 9cc4e15f46 handle type command on names that contain slashes, and print a : in the not
found case. From FreeBSD.
2000-11-01 19:21:41 +00:00
mycroft 8f48358936 Wrap malloc() calls with an INTOFF/INTON pair. Fixes PR 8414. 2000-10-21 04:37:17 +00:00
phil 34ad57a779 .Bl takes parameter "-offset indent", not "-indent". 2000-09-21 21:04:56 +00:00
kleink 2caf6aacdd For commands and utilities, use EXIT STATUS rather than RETURN VALUES as
appropriate (and documented in mdoc(7)).
2000-09-04 07:30:07 +00:00
hubertf 1cb54f68ac Add 'RETURN VALUE' section header. 2000-08-28 02:11:04 +00:00
cgd 2a1ee59131 un-__P functions declared in parser.h. host programs include parser.h,
and so it shouldn't use __P.  (this should probably be done better, by
not declaring the parser functions in headers used by host programs,
but this works well enough.)
2000-07-27 04:09:27 +00:00
cgd 96df053cba host program portability: set infp to stdin at runtime, since apparently
some systems (e.g. linux) define stdin in such a way that it can't
be used to initialize values at compile time.
2000-07-27 04:06:49 +00:00
cgd 28728fd305 host program portability: don't use <sys/cdefs.h>, __COPYRIGHT(),
__RCSID(), or __P().  (these programs have been de-__P()'d.)
Repeat after me: "Not all cross-compilation host systems are NetBSD."
2000-07-18 19:13:20 +00:00
jhawk 9d53f2aee6 Various mandoc updates to the Builtins
section; mostly .Ic, a few other nits.
2000-07-18 01:55:48 +00:00
jhawk 45a8e6b7e3 Note the meaning of 'trap 0' (execute on exit from shell) 2000-07-17 21:18:47 +00:00
matt e2056eada9 include <stdlib.h>, <string.h>, or whatever as appropriate to shut up
gcc 2.96
2000-07-03 03:26:17 +00:00
elric e6bccfe4be Back out previous vfork changes. 2000-05-22 10:18:46 +00:00
elric f5dccf4728 When vforking ensure that the environment passed to exec is built before
vforking as a set of local variables which can be popped by the parent.

Addresses bin/10124.
2000-05-17 07:37:12 +00:00
elric e8b0f2b813 INTON and FORCEINTON modify global variables, and so should not be
executed while we are vforked.
2000-05-15 03:42:48 +00:00
elric c55fa30be8 Added includes for waitpid, sys/types.h and sys/wait.h. 2000-05-13 21:11:45 +00:00
elric a0ef2ea948 In order to use __NetBSD_Version__, I needed to include sys/param.h. 2000-05-13 21:11:16 +00:00
elric 0eece24a3a Unused variable pgrp on line 576. 2000-05-13 20:59:41 +00:00
elric 4aeaa113a7 Quick fix.
jobs.h:91: warning: declaration of `vfork' shadows global declaration
2000-05-13 20:56:08 +00:00
elric 756a2ca1bd Now we use vfork(2) instead of fork(2) when we can. 2000-05-13 20:50:14 +00:00
simonb d2f6a4723d Include <errno.h> instead of using "extern int errno;". 2000-04-14 05:54:20 +00:00
simonb 51ee9dc68d Don't declare 'extern opt*' getopt variables. 2000-04-14 05:52:56 +00:00
christos b252543484 PR/9847: Geoff C. Wing: Make test(1) a builtin. 2000-04-09 23:27:03 +00:00
soren 1594850f00 Fix doubled 'the' in comment. 2000-03-13 22:46:59 +00:00
christos 9fcfbaea4d Fix problem where commands that caused exitstatus != 0 inside loops did
not cause the shell to exit when -e was set.
2000-02-09 20:26:53 +00:00
christos d6ac7627ea Fix bin/9184, bin/9194, bin/9265, bin/9266
Exitcode and negation problems (From Martin Husemann)
2000-01-27 23:39:38 +00:00
hubertf a8bbeb8a4b Add under which conditions the "read" builtin returns success/failure.
Suggested in PR 8813 by Eric Mumpower <nocturne@arepa.com>
1999-11-16 22:03:25 +00:00
mrg 1b23e7d142 back out previous; it causes /etc/rc to break on my alpha and other lossage as reported in PR#8614 1999-10-13 00:59:10 +00:00
pk ef45922abf Backtrack `exitstatus' to make the shell really ignore the status
of `tested commands' as in this example:

	set -e
	true; false && echo "not reached"
1999-10-10 21:22:24 +00:00
pk 8c06f48e15 Sprinkle some `const's in DEBUG bracketed code. 1999-10-08 21:10:44 +00:00
bouyer d406538de6 xref sysctl(8) (for proc.<pid>.rlimits) 1999-09-28 14:54:41 +00:00
mjl 4c5c12b3f0 Mention -c option to sh(1), noticed by Matthew Aldous in PR/8499. 1999-09-27 19:34:25 +00:00
mycroft 2806df576c It turns out that the code disabled in revision 1.30 *does* have an important
function (which nobody was able to explain): it's critical to allowing a
complex command run from an interactive shell to be terminated.  So, reinstate
it and fix it correctly.  See the comment if you really want the gory details.
1999-08-31 08:58:47 +00:00
christos 3d42469030 compile with WARNS = 2 1999-07-09 03:05:49 +00:00
christos f914977fae add -q in the synopsis line 1999-07-06 14:01:01 +00:00
christos 02048e84df PR/7814: Matthias Scheler: shell does not fork for builtins in backquotes,
leading to unexpected behaviour. Disable the no-fork optimization for now.
We need to revisit this and keep enough state around to recover from such
changes.
1999-06-26 16:31:47 +00:00
he e97b0193be Fix for bin/7502, from Tor Egge / FreeBSD. Their commit message:
> During variable expansion, the internal representation of the expression
> might be relocated.  Handle this case.
1999-04-30 17:54:17 +00:00
he 4e69294c60 Correct a rather obvious typo (once Tor Egge pointed it out to me)
in the last change.
1999-04-06 21:05:27 +00:00
mycroft 2e23138ad7 If we exit due to a SIGINT, do it with raise() so that the wait status is
correct in the parent.
1999-04-05 15:00:28 +00:00
mycroft c06643b836 Disable bogus-looking code that cause us to throw away SIGINTs. 1999-04-05 14:59:35 +00:00
christos 832949b912 When we execute commands from a shell script, make sure that the signals
are being caught (reported by Alexis Rosen), similar to the -c case.

#!/bin/sh
vi "$@"

^C when the script is running...
1999-03-27 13:46:19 +00:00
christos 28607542af PR/7231: Havard Eidnes: Shell quoting/trimming problem 1999-03-26 15:49:34 +00:00
ross 4b1d9297dc Make the `...' actually appear in the case/esac syntax section.
Fix a space botch in the $@ example.
Kill warnings caused by the effective but wrong use of \[ and \] to
perform the function of \&[ and \&].
1999-03-23 02:29:29 +00:00
garbled f124765044 More and more .Os cleanups. .Os is defined in the tmac.doc-common file,
so we shouldn't override it with versions in the manpages.  Many more to
come.
1999-03-22 18:25:43 +00:00
castor dc67d78474 Add '#include <sys/types.h>' since that's where int8_t and u_int8_t can
usually be found.
1999-03-08 17:55:20 +00:00
wrstuden 6790f70d78 Make cross-building from i386 to powerpc (from signed to unsigned char)
ports work right.
1999-02-23 01:50:26 +00:00
christos 96a46ed7b1 Fix off-by-one error in the starting point to search for an arithmetic
expression.
1999-02-06 17:23:09 +00:00
tron 96dc868859 Remove "arith.h" while cleaning. 1999-02-05 22:19:47 +00:00
christos 1666f88d5d Fix the -c problem differently. We cannot just ignore SIGINT etc, otherwise
we cannot interrupt sh -c <command>
1999-02-05 21:21:27 +00:00
christos b4c9a78425 PR/5577: Craig M. Chase: sh does not build with PARALLEL set.
- Added YHEADER in Makefile, removed arith.h and adjusted the sources.
1999-02-05 07:52:51 +00:00
christos 6e50d7a816 PR/4966: Joel Reicher: Implement <> redirections which are documented in
the man page.
1999-02-04 16:17:39 +00:00
christos dd65252560 PR/1788: Shinya Taniguchi: sh -c does not setup signals properly.
[Reminded to me by Alexis Rosen -- thx!]
1999-02-04 11:20:40 +00:00
cjs 9063efaca0 Add -q option, which when used with -v and/or -x, turns off the tracing
during the execution of /etc/profile, .profile and $ENV.
1999-02-04 00:27:07 +00:00
itohy 362c3e31c9 The builtin . (dot) command no longer sees the current working directory
even if the specified file is not in the PATH.
This change enforces security and makes it conform to POSIX.

Closes PR #6794.
I thought Christos committed this but not appeared yet. :)

The setstackmark()/popstackmark() pair in dotcmd(), used for freeing
stack storage possibly allocated by find_dot_file(), is redundant for now
since dotcmd() is surrounded by another pair in evalcommand().
This redundancy, however, may help future modifications
(suggested by Christos).
1999-02-02 15:49:52 +00:00
kleink f71d010d24 Add support for the export and readonly -p option. 1999-01-28 18:11:50 +00:00
mycroft 1fbf0781c6 Patches from Tor Egge (via Havard Eidnes) to fix various bugs in field
splitting and combining.
(Note: Some of this are not strictly bugs, but differences between traditional
Bourne shell and POSIX.)
1999-01-25 14:20:56 +00:00
christos e1849b79b1 PR/6213: Urban Boquist: /bin/sh does not handle a trapped signal correctly
The problem was that system calls got restarted after a signal,
	 instead of returning EINTR. Thus the read builtin, had no way to
	 know that a signal occured that could change the course of execution.
	 Since the code has sprinkled checks for EINTR all over the place,
	 it is supposed to work properly with non restartable syscalls.
	 The fix is to use siginterrupt(signo, 1), before setting a signal
	 handler, to make sure that system calls don't get restarted.
1999-01-18 16:18:04 +00:00
garbled f33f4be925 Massive fixup:
Rewrite man page in mandoc format rather than nasty man format.
Fix a ton of parsing errors, and generate proper .Xr's.
document all known environment variables.
suggest ksh rather than bash.

The last two fix PR #1966.  Wheee!

Somebody with access to the POSIX spec needs to go in here, and document
our adherence, or lack thereof.
1999-01-11 19:34:53 +00:00
msaitoh 576a5fdc92 fix some bugs 1998-11-17 14:16:32 +00:00
garbled b4e6f9c37a Modify to better document getopts. This fixes PR# 704. Much thanks to
Christos for helping me out with this.
1998-10-29 23:23:36 +00:00
ross 7fc1302b5d The recent cross-compile changes broke the build of x_sh. Properly use
${.IMPSRC} instead of the broken ${.CURDIR}/thing.c.
1998-10-08 00:29:38 +00:00
itohy ef88b5d2bd Fixed memory leak on old style command substitution
such as  sh -c 'echo `echo foo`' .
The memory allocated with ckmalloc() at
parser.c:1349:readtoken1() (search for "done:" label)
was never freed.

I changed this to use 'string stack' framework of Ash.
Note that a string on string stack is properly freed on
exception and end of command parsing, and no explicit free
or signal handlings required.
See TOUR for an overview, and memalloc.[ch] for details
of string stack.
1998-09-26 20:56:33 +00:00
christos 26e51b35ac include <stdlib.h> to get the prototype for free() 1998-09-26 19:28:12 +00:00
itohy cc484b787f The return value of setmode(3) is a pointer to malloc()'ed area
and must be freed to avoid memory leaks if called repeatedly.
The leaks occured on symbolic umask command, such as "umask go-w",
which is undocumented.
1998-09-24 17:49:48 +00:00
wrstuden 1037acbf7e We don't generate .o's anymore for helper programs, so don't CLEANFILES them. 1998-09-12 18:58:41 +00:00
wrstuden d10063d5c7 Patch to make sh cross-compile right. mksyntax reports unsigned char for
powerpc, and signed for m68k & i386.
1998-09-12 18:55:07 +00:00
mycroft ee9e50eacb Be more retentive about use of NOTREACHED and noreturn. 1998-07-28 11:41:40 +00:00
mycroft 9dc385beb1 Delint. 1998-07-28 05:31:22 +00:00
christos d06f150426 PR/5848: David Holland: Use PIPE_BUF instead of hardcoding 4k 1998-07-27 17:12:45 +00:00
mycroft 5dd823ab5d const poisoning. 1998-07-26 19:44:12 +00:00
ross 69228f8bd8 Small edit to n1>&n2 description. 1998-07-04 06:52:07 +00:00
ross ac875dda03 Fix a set of bugs where a cd of a relative pathname or a cd through a
symbolic link would not set PWD.
1998-05-21 16:50:40 +00:00
christos efee39278b Simplify interface for general use. 1998-05-20 01:36:14 +00:00
christos f792cdd756 Cast is*() args to unsigned chars in case the ctype macros are implemented
using arrays.
1998-05-20 00:32:05 +00:00
christos 96133865eb cast pid's to longs for OS's where this is the case. 1998-05-20 00:31:11 +00:00
christos 338ea4cec8 fix bug where if moving in history during a multi-line event, the
append to history event would end up in the last event where the history
was moved to instead of the multi-line event; reported by Mycroft
1998-05-20 00:29:26 +00:00
christos 3d8b8b2ed2 Fix dangling else warning. 1998-05-20 00:27:56 +00:00
christos 3ebdac1759 Portability fixes for a non flex based lexical analyzer. 1998-05-18 22:50:20 +00:00
christos c6e03280d4 Need stdlib.h 1998-05-18 22:48:53 +00:00
christos d2ded939ef PR/5315: Dan Winship: options parsing code should print errors to stderr. 1998-05-02 18:04:09 +00:00
cgd 2072394059 move OBJS depenency on built headers to after include of bsd.prog.mk, so
that things are built in the right order on 'make cleandir && make' (i.e.
so that the headers are properly built).
1998-04-19 05:22:08 +00:00
lukem d6c354cb4b * remove CFLAGS+=-w for powerpc (added in 1.26):
- it was in the wrong place
	- makefiles shouldn't override CFLAGS; only CPPFLAGS and COPTS
	- christos fixed unsigned char stuff in 1.33 which should
	  remove the need for -w anyway
* move .include <bsd.prog.mk> to EOF
1998-04-13 12:06:48 +00:00
tv 482063559a .y.c <sys.mk> rule fixes. Don't create a y.tab.h file unless asked for,
and use smarter creation of the header file.
1998-04-09 00:32:31 +00:00
fair 667e4d4cd1 fix default PATH to be <paths.h> _PATH_DEFPATH 1998-04-07 21:15:33 +00:00
fair 618cca243b Change a few things to reference /usr/include/paths.h instead of local
references. Fixing the default PATH is a bit more effort.
1998-04-07 10:16:04 +00:00
veego 7f307512f9 Another try to make this work again. Lets hope that the we don't need a 4th
fix for it.
1998-03-30 12:06:48 +00:00
mrg 6e35073fed make this work again when . is not in $PATH 1998-03-30 10:07:16 +00:00
christos 0328c41456 Pr/5221: Jason Thorpe: Simplify sh Makefile, so that builts from other
directories work.
1998-03-29 09:27:40 +00:00
mrg a26bae1e08 - change "extern" variables into int's
- remove extern'd variables not actually referenced
- don't use char as an array index
1998-03-29 04:41:43 +00:00
christos 04784d87fa Fix the VSTRIMRIGHT* bugs... The problem was not the string length computation,
but lack of '\0' termination. Factor this segment out as common code too, while
I am there.
1998-03-23 18:21:02 +00:00
christos 19e7771baa off by one error in ${%%} 1998-03-10 19:11:07 +00:00
christos 7cfc52b208 PR/5001: Tom Yu: cd ./ does not work. 1998-02-17 02:57:16 +00:00
christos ce0d4f06a6 Previous fix broke $var quoting. Try again differently :-) 1998-02-17 00:16:16 +00:00
christos d8a1d3710c Re-enabled EXP_RECORD 1998-02-05 08:34:49 +00:00
christos f7c8df6d68 Fix bug introduced by EXP_RECORD, where in case there was a variable expansion
involved in the `for' list, the list was recorded twice, leading to incorrect
argument expansion.
Introduce ifsfree() function that free's the IFS region list, GC'ing duplicated
code.
1998-02-05 08:32:00 +00:00
thorpej b65b5cae9e Sigh, have to cast pointer diffs to long. 1998-02-04 23:49:25 +00:00
thorpej a40a144d00 Fix printf formats so they work on the Alpha. 1998-02-04 20:10:16 +00:00
mikel a235399817 back out last change until christos fixes EXP_RECORD; PR 4932 1998-02-04 06:25:55 +00:00
christos 5a36c00160 PR/4851: Benjamin Lorenz: In the "for <var> in <args>" construct <args>
was not marked as a region to be handled by ifsbreakup. Add EXP_RECORD
to indicate that the argument string needs to be recorded.
1998-01-31 12:45:06 +00:00
christos 2b259b0600 - Add gcc attributes to printf like functions
- Fix format strings to be const
- Fix buffer length to be size_t
- Add %p format
- Avoid code duplication in varargs/stdarg cases
1998-01-31 12:37:55 +00:00
christos 7faabd5800 Include our local includes after the system's ones. 1998-01-31 12:36:16 +00:00
christos 71868e12e2 Fix printf format. 1998-01-31 12:34:12 +00:00
christos e3f5fb922f BSD4_4 is a standard symbol in <sys/param.h>; make sure that files
that need this defined, include <sys/param.h> and don't define it in
the Makefile. Add a comment to that effect.
1998-01-21 10:47:37 +00:00
pk 5d9692a740 Define BSD4_4: quad_t's in struct rlimit; 1998-01-20 22:43:34 +00:00
christos 38c84eeda3 test for the boundary condition in the previous trailing blank fix 1998-01-16 16:26:22 +00:00
christos 2708e4180f PR/4805: Ty Sarna: read builtin does not remove trailing blanks. 1998-01-15 19:39:11 +00:00
christos 505573954e Unfortunately (as I expected) the previous change broke:
sleep
    cmd='set `type "sleep"`; eval echo \$$#'
    which=`eval $cmd`
    echo $which

because the region did not get recorded at all, and it was interpreted as
a single word. I modified the code to keep track when the result of a
backquote expansion has been recorded to avoid recording it twice. I still
feel that this is not the right fix... More to come.
1997-12-01 14:43:20 +00:00
christos 81aad04920 Remove local declaration of getenv(); 1997-12-01 14:40:16 +00:00
christos b7e4df7784 PR/4547: Joern Clausen: Incorrect argument expansion in backquote variable
assignment. E.g.
	echo ${foo:=`echo 1 2 3 4`}
prints:
	1 2 3 1 2 3 4
because when the arquments are not quoted, the backquote result
gets recorded twice.  The fix right now is to comment out the
record_region() call in expbackq().  I hope that it does not break
anything else.
1997-11-30 20:57:33 +00:00
cjs af5956aa6b Make this compile with -DSMALL and warnings on. 1997-11-12 03:40:55 +00:00
kleink 3780e6aa5d Per 1003.2, the (builtin) read utility shall treat the backslash as an
escape character (including line continuation), unless the `-r' option
is specified:
* adopt to this behaviour, add the `-r' option to disable it;
* remove the `-e' option, which was previously necessary to get this behaviour.
1997-11-05 14:05:28 +00:00
christos 82ec25620f pid should be pid_t and status should be int! Avoid alignment problems... 1997-10-15 13:23:10 +00:00
christos 946049095f PR/4257: Jaromir Dolecek: Update for libedit interface change. 1997-10-14 15:06:42 +00:00
christos e230a48b57 CFLAGS->CPPFLAGS 1997-10-10 19:47:50 +00:00
christos 7f2a271743 PR/3662: David Holland: Make /bin/sh use the symbolic macros for wait(). 1997-10-08 20:31:52 +00:00
lukem 92d7aa0376 getopt returns -1 not EOF 1997-09-14 07:43:56 +00:00
thorpej 23eb2db171 Avoid a segv in bltinlookup() reported by Ronald Khoo <ronald@demon.net>
in PR #3929, fix submitted by hiroy@NETCOM.COM (Hiroyuki Ito).
1997-08-26 20:09:59 +00:00
christos 23edbe3557 Remove WARNS=1 from all the subdirectory Makefiles, and add it to Makefile.inc
now that all /bin has been cleaned.
1997-07-20 22:36:20 +00:00