Commit Graph

577 Commits

Author SHA1 Message Date
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
christos c996803cad PR/3888: Chris Demetriou: type command-with-slash prints
$PATH[0]/command-with-slash...
1997-07-20 21:27:35 +00:00
thorpej d891aff808 Cast the result of pointer arithmetic to "long", and use %ld to print it. 1997-07-18 17:46:59 +00:00
christos 18ad58a639 PR/3866: bayer@informatik.uni-leipzig.de: core dump using xon script.
cmdenviron is pointing to varlist.list; varlist gets reset everytime
you enter evalcommand, but cmdenviron does not. The wonders of global
variables...
1997-07-15 17:49:15 +00:00
christos 1eb178df64 Fix Sparcworks warnings. 1997-07-15 17:45:53 +00:00
christos bb5e01d099 Don't re-define setjmp/longjmp in the svr4 case 1997-07-15 17:44:32 +00:00
phil 1d304ac34c Add a missing ) in the description of the builtin "set". 1997-07-10 23:07:04 +00:00
phil 64eb899e5a Make code agree with man page in processing expansion of "$*".
Fix from PR 2647.
1997-07-07 20:41:10 +00:00
christos 5accccd051 Fix problem introduced in yesterday's commit that broke both signed and
unsigned character machines. So that people don't have to reverse engineer
this again:
	mksyntax detects if characters are signed or not and builts a syntax
	table that has a base of 129 for signed characters or 1 for unsigned
	characters. This is so the largest negative signed char [-128] + the
	base == 1. 0 is special and means end of file in both cases. PEOF
	is -1 for the unsigned character case and -129 for the signed
	character case, so that syntax[PEOF + base] == syntax[0] == CEOF
	So PEOF has to be -1, but it is explicitly compared with
	unsigned characters on machines where characters are unsigned.
	The quick fix is to define UPEOF the (unsigned char) version of PEOF
	and use that. A better fix is to always use unsigned characters
	when referencing symbol table entries, but that would require
	extensive changes to the shell. So to summarize

	syntax[0] == CEOF, base + PEOF == 0

		unsigned	signed
	base	1		129
	PEOF	-1		-129
1997-07-05 21:25:09 +00:00
christos 687f7852d9 Make the syntax tables work on machines where characters are unsigned. 1997-07-04 21:40:55 +00:00
christos cd799663e4 Fix compiler warnings. 1997-07-04 21:01:48 +00:00
christos 28f5c57bd5 Don't roll own rules to build helper programs.
Add WARNS
1997-07-04 21:00:36 +00:00
christos cbf48b75c7 PR/3827: Wolfgang Rupprecht: cd ./. core dumps
Warning cleanups
1997-07-04 20:59:40 +00:00
lukem a1267d0c71 add auto-generated token.h to dependancy for ${OBJS}.
not everyone runs "make depend" ...
1997-06-16 02:42:38 +00:00
cjs cddf57d923 Add documentation for ulimit command, courtsey of
Eric Fischer <eric@fudge.uchicago.edu>.
1997-05-23 19:40:30 +00:00
veego 3e90f9b423 Add mkinit.o mknodes.o mksyntax.o to CLEANFILES 1997-05-15 10:03:24 +00:00
mycroft cc4a1553a1 Eliminate bogus redefinitions of standard targets. 1997-05-09 07:50:03 +00:00
gwr 10e180cc49 Back out the .PATH.c changes. The .depend problem (and others)
will be fixed using the new .NOPATH make feature instead.
1997-05-08 21:11:01 +00:00
gwr 012e528f2e Use .PATH.c: ... 1997-05-06 20:44:56 +00:00
christos fb758fd82b PR/3452: Jerry Peek: Redirections of unopened fd to file failed.
for arg in a b c
    do
	echo hi this is $arg 1>&3
    done 3> foo
1997-04-21 12:38:25 +00:00
thorpej 062f26f33b - XXX Inhibit warnings on PowerPC for now - there are lots of
"char is unsigned" problems here.
- Add rules for mkinit, mknodes, and mksyntax that use the HOST_*
  facilities, for cross-compiling.
1997-04-17 08:13:26 +00:00
christos 3a468199cb #if __STDC__ -> #ifdef __STDC__ 1997-04-11 23:08:40 +00:00
christos 360e930d42 Make this work on systems that don't have quads 1997-04-11 23:08:15 +00:00
christos 2c8f740e5c __svr4__ -> __SVR4 1997-04-11 23:07:47 +00:00
christos 7ea7f895f5 Use #ifdef __STDC__ instead of #if __STDC__ 1997-04-11 23:06:51 +00:00
christos 92cdde85e8 Fix so that this compiles on systems without quads and remove the double
inclusion of varargs/stdarg
1997-04-11 23:05:43 +00:00
christos 70bb105c67 Pointer arithmetic on void * is illegal but gcc does not care. 1997-04-11 23:03:08 +00:00
christos 23745b89db Don't call getpwd() because if that fails the shell cannot start. (from scott) 1997-04-11 23:01:44 +00:00
christos f726a3c453 Rename pread to preadfd 1997-04-11 23:00:40 +00:00
christos 3bddaec49b add forward declaration of union node; 1997-04-11 22:58:40 +00:00
christos 7efa5addb4 Track $TERM and call the appropriate editline(3) routine to update the
terminal type.
1997-04-11 22:45:38 +00:00
christos a0fa692d3b PR/3352: From Hiroyuki Ito: ${#1} was not being expanded properly if there
was a need to allocated another stack block.
1997-03-18 18:54:40 +00:00
christos 7accaec421 NO_HISTORY->SMALL 1997-03-14 01:42:18 +00:00
christos 6042831b7e Fix problems with -DNO_HISTORY 1997-03-13 21:57:32 +00:00
mycroft 3a59e5e8e3 Set input files to close-on-exec mode. 1997-03-13 20:07:49 +00:00
mouse 412433b44c alternate -> alternative, per PR 2643 1997-03-08 13:26:20 +00:00
christos 6b7623a681 Fix PR/3289: upon initialization check if $PWD contains the right directory
and use it. We also maintain $PWD now, like the rest of the
	     shells.
1997-03-07 21:36:19 +00:00
christos 4a521d359f varisset fixes:
- treat $0 specially since it is not in shellparams
	- check the number of parameters instead of walking
	  the parameters array to avoid checking against the
	  null terminated element.
1997-03-03 19:26:18 +00:00
christos edc5dadbab PR/3269: Off by one in varisset(), caused variable substitution not to
count the last positional parameter as set.
1997-03-01 19:33:29 +00:00
christos a5aaf55cf3 Fix PR/3258 sh -c 'echo $0' causes segmentation fault. 1997-02-25 17:51:50 +00:00
christos 680690d33c add type builtin. 1997-02-06 23:24:52 +00:00
christos 6f224ae59f Fix parsing problem introduced in the previous ${10} fix, where $#digit
or $digit# would get mis-parsed as a positional parameter.
1997-01-26 18:05:34 +00:00
christos 633ceb6db5 - varisset(): In positional arguments, take into account VSNUL so that:
set -- ""; echo ${1:-wwww} works.
- when expanding arithmetic, discard previous ifs recorded regions, since we
  are doing our own scanning. x=ab; echo $((${#x}+1)) now works.
- in ${var#word} fix two bugs:
   * if there was an exact match, there was an off-by-one bug in the
     comparison of the words. x=abcd; echo ${x#abcd}
   * if there was no match, the stack region was not adjusted and the rest
     of the word was getting written in the wrong place. x=123; echo ${x#abc}X
1997-01-24 17:26:28 +00:00
christos 3d5f212ba8 enable parsing of multi-digit positional arguments i.e. ${10} works and it
is not a bad substitution.
1997-01-24 17:15:56 +00:00
tls 48250187e6 kill 'register' 1997-01-11 02:04:27 +00:00
cjs 5678a13f1b Re-introduce some code from 1.14 (with modifications) to make the
shell's idea of the current working directory match reality when
symlinks (or anything else we can't stat) are traversed with the
cd command. However, this does not print out the cwd after cd
traverses symlinks, as it used to, though the capability is still
there should one want to use it.
1996-12-22 08:34:34 +00:00
christos a00e49c200 Getopts bugs again (I'll never get this right).
- make sure that OPTIND is set correctly even in the absence of options.
- don't keep stale state between getopts calls.
1996-12-15 20:37:09 +00:00
christos 340077b543 - fix parsing bug reported by mycroft: ! was only recognized in the beginning
of pipelines. Now we are recognizing it everywhere like ksh, so:

	! if [ a = b ]; then ! echo c && ! true; else ! echo d; fi

  works.
1996-11-25 20:22:00 +00:00
christos 9530a32719 Fix bug in getopts code where the argument list got truncated.
From Todd Miller.
1996-11-24 20:48:01 +00:00
christos 07aeb5b266 remove a debugging printf that was left from the last POSIX error code fixes. 1996-11-09 01:04:07 +00:00
christos ccce082dd2 Fix miscellaneous getopts problems:
- the 3 argument version of getopts would not reset properly
- OPTARG did not get cleared after a non argument option was found
- OPTIND was not set properly after a non argument option.
1996-11-06 01:17:10 +00:00
christos 846dce0ee3 Fix problems that gcc -Wall found (from Todd Miller, OpenBSD) 1996-11-02 18:26:03 +00:00
christos a4ad4c0efc A correction to the previous patch from Todd Miller. 1996-11-02 18:07:08 +00:00
christos 27e15e5bbc echo ${1:-empty} did not do the substitution; from Todd Miller (OpenBSD) 1996-11-02 17:47:41 +00:00
cgd 8ba64baaaf add builtins.h to the list of (built) headers depended on by ${OBJS}, so
make from 'cleandir' works.
1996-10-22 13:22:19 +00:00
abrown e613224229 Remove leftover printf("here") from last change. 1996-10-19 02:38:36 +00:00
christos bc73cf950a PR/2808: Remove trailing whitespace (from FreeBSD) 1996-10-16 15:45:03 +00:00
christos afb80e9b13 PR/2808: Add a definition for warnx() (from FreeBSD; currently unused) 1996-10-16 15:28:10 +00:00
christos 2b0a187f34 PR/2808: Use .Nm macro properly. (from FreeBSD) 1996-10-16 15:27:03 +00:00
christos 1a523dd56b PR/2808: - Don't use p++ in macros.
- Hash using unsigned numbers.
	 (from FreeBSD)
1996-10-16 15:24:31 +00:00
christos 68b1dcea6d PR/2808: Don't define DEBUG and #ifdef out functions not needed when DEBUG
is not defined (from FreeBSD).
1996-10-16 15:21:49 +00:00
christos 3b66e0cada PR/2808: Add HISTORY section and documentation of getopts. (from FreeBSD) 1996-10-16 15:20:01 +00:00
christos da8c1311a3 PR/2808: fix redirection to the same file descriptor
better error messages for failed pipes
	 (from FreeBSD)
1996-10-16 15:16:04 +00:00
christos d8c242f0ae PR/2808: - detect eof inside backquotes
- handle && and || shortcircuits properly
	 - tokens.def -> tokens.h
	 (from FreeBSD)
1996-10-16 14:53:23 +00:00
christos 10a76271de No need to have 2 declarations for the same constant string, one for K&R and
one for STDC...
1996-10-16 14:51:24 +00:00
christos fd8c99438e PR/2808: POSIX 1003.2: first arg after -c cmd is $0, remainder $1...
(from FreeBSD)
1996-10-16 14:49:56 +00:00
christos 14185e5152 PR/2808: Kill use of error2() (from FreeBSD) 1996-10-16 14:49:03 +00:00
christos 71ab1d0aed PR/2808: tokens.def -> tokens.h 1996-10-16 14:47:49 +00:00
christos 03ba3cf0d6 PR/2808: Use the <ctype.h> functions instead of our homegrown tables to
determine if a character is alpha or alphanumeric, so that NLS
	 works... now if only our NLS really worked... (from FreeBSD).
1996-10-16 14:46:35 +00:00
christos f6c00506fc PR/2808: Remove extraneous newline from error message (from FreeBSD) 1996-10-16 14:44:28 +00:00
christos 00a9e38ee8 PR/2808: #undef things that we #define to avoid duplicate definitions.
(from FreeBSD)
1996-10-16 14:43:37 +00:00
christos a20d79429a PR/2808: Don't include <sgtty.h> unless OLD_TTY_DRIVER is defined.
Remove extraneous newline from error messages.
1996-10-16 14:42:20 +00:00
christos 435812e77d PR/2808: Remove extraneous newlines from error routines (from FreeBSD) 1996-10-16 14:40:32 +00:00
christos 4b99c4d748 PR/2808: Fix parsing of $n where n > 9 (from FreeBSD) 1996-10-16 14:38:58 +00:00
christos 2a9c11dd53 PR/287: Shell does not exit with 126/127 when permission denied/
command not found. Add extra exception type and generalize
	error handling routines to take that exception type. Use
	a global variable exerrno to keep the last exec error.
1996-10-16 14:35:42 +00:00
christos 886c875a97 PR/287: Exit with 127/126 when command is not found/permission denied.
PR/2808: don't bomb out on "set -e; false && true"
1996-10-16 14:31:57 +00:00
christos dd6abbc5c3 PR/2808: Handle cd "". This is for systems where "" != "." 1996-10-16 14:29:42 +00:00
christos aded8d4c14 PR/2808: tokens.def -> tokens.h 1996-10-16 14:24:56 +00:00
christos 3ec8ea2b0e PR/2808: Depend and clean fixes from FreeBSD 1996-10-16 14:23:51 +00:00
thorpej 47f181309b If getcwd() fails, dang it, I want to know _why_. 1996-09-18 22:47:48 +00:00
mycroft c65b90450d ioctl(TIOC[GS]PGRP) -> tc[gs]etpgrp() 1996-09-17 14:44:05 +00:00
christos 4d9c694460 Apply PR#2721 from VaX#n8: make man page more lucid in places. 1996-09-02 21:28:21 +00:00
christos 29cad877cd Don't infinite loop with:
unset var
	echo ${var:=}
1996-09-02 21:25:52 +00:00
christos beb57fb35d - Add function callback capability when variables are set.
- Add setvarsafe that returns an error instead of longjmp() to the
  error code.
1996-06-25 16:49:05 +00:00
christos cc31700a92 - Add getoptsreset to be used as a callback function when OPTIND is set.
This is used to implement the POSIX behavior when OPTIND=1
- Call setvarsafe instead of setvar. If one ran
	"getopts optstr badvariable"
  where badvariable contained an illegal variable name, there was no way
  to recover, since setvar() would longjmp on the error.
1996-06-25 16:47:43 +00:00
christos 02b3c16118 change sethistsize() to take the history size as an argument so it can
be used directly by the new variable callback functions.
1996-06-25 16:43:33 +00:00
christos 9a738ef22d const poisoning. 1996-06-25 16:40:38 +00:00
christos 70ad20e9f1 Include header files to get function prototypes; don't use home grown ones. 1996-06-25 16:40:06 +00:00
christos 0bc88b2434 getopts fixes:
1. OPTIND value was not computed correctly when the argument was part of the
   option string (i.e. for "l:" "-l 1" was working "-l1" was not). (PR/2505).
2. OPTARG was not being unset in case of errors [in the non POSIX error case].
3. optvar could be set to random values.
4. Option string starting with a : was not treated specially as POSIX
   specifies (if the option string starts with a :, then there is no
   error printed when there are missing option arguments or illegal options,
   and OPTARG and optvar are being set specially).
5. Implemented getopts "opts" optvar [arg]. The optional argument case
   was not implemented.

To do:
- what does Posix say about resetting the getopts state? Bash does it
  by setting OPTIND=0; is that correct? Should we be doing the same thing?
- should we be using getopt(3) for everything internal to the shell? Is that
  feasible because we might need to handle multiple invocations at once.
1996-06-04 21:00:09 +00:00
christos 66824391d1 Fix PR/2504: return with no args returns 0 instead of the return value of
the previous command in functions
1996-06-03 12:21:17 +00:00
cgd edc0ef345c Fix growstackblock() 'newlen' calculations:
(1) it needs to be ALIGNed for both halves of the 'if,' and
	(2) if you're going to claim that you now have ALIGN(newlen)
	    bytes left, you should have actually allocated
	    ALIGN(newlen), rather than just 'newlen' bytes.
1996-05-20 14:49:32 +00:00
christos 55a41e8abb Close PR/2384 backquoted backslash-newline was not eaten. 1996-05-09 19:40:08 +00:00
pk 0b9acf16f8 Return zero status if `else' clause is empty. 1996-03-06 14:49:29 +00:00
christos b09ffc42b1 - parser.c: Fix prompting in old style backquote expansion. Fixes PR/2139
and many user complaints why the shell hangs in echo "`"
- eval.c:   Fix exitstatus invalid resetting in `if' statements were:
		if (exit 3); then
			echo foo $?
		else
			echo bar $?
		fi
	    printed 'bar 0' instead of bar 3
1996-03-05 21:03:52 +00:00
jtc 16f5230c39 Changed so that cd builtin doesn't do wierd stuff when cd'ing through
symlinks.  From Chris Demetriou <cgd@NetBSD.ORG>.  Fixes PR #1776.

Changed so that INTOFF/INTON are paired in getpwd().  From Matthias
Pfaller <leo@marco.de>.  Fixes PR #2130.
1996-03-01 01:58:58 +00:00
mycroft b5b9e1d0fa Fix problems with the way init.o is built:
* Prevent gratuitous rebuilds when nothing has changed.
* Make sure it's rebuilt if a .h file is updated.
From Mike Long, PR 1454.
1996-02-18 12:29:18 +00:00
christos d3aec2060d Fix PR/2070: Ksh style variable modifiers were broken in /bin/sh, from
enami tsugutomo
1996-02-12 15:11:41 +00:00
christos ff008dabf6 Fix PR/1760, where 'cd -' before any other command could cause a reference
to an uninitialized pointer. Use getcwd() to get the current working directory,
instead of forking /bin/pwd [per Scott's suggestion]
1995-11-19 23:27:37 +00:00
christos c22dddc4e0 Parallel make fixes. 1995-10-22 00:15:02 +00:00
christos 893ade3fac - fix PR1620, -DNO_HISTORY did not work.
- restore parsing state after parsing old style command substitution.
  The ';' in '`echo z;`' broke the following:
	for i in 1; do
		cat > /dev/tty << __EOF__
		`echo z;`
		__EOF__
	done

cVS: Enter Log.  Lines beginning with `CVS: ' are removed automatically
1995-10-19 04:14:37 +00:00
christos 92380da725 fixed previous booboo that broke command line editing input. 1995-10-06 21:38:18 +00:00
christos c1b02d9bff - Fix -v flag, so that it works properly when the shell reads from scripts.
- Bad style to fix my own PR, but I'd like to commit the parallel make
  changes soon, and this is a necessary prerequisite.
1995-09-26 13:25:19 +00:00
jtc d4fe82df8d Handle %q format directive; from Mike Long (PR #1454). 1995-09-14 16:19:06 +00:00