Commit Graph

562 Commits

Author SHA1 Message Date
Jesus R. Camou
a886288efd o Discuss the ways to escape an alias.
o Fix the alias syntax lines.
o Refer to the Aliases subsection.

PR:		docs/84914
Submitted by:	garys
Approved by:	trhodes (mentor)
MFC after:	3 days
2005-08-29 06:47:43 +00:00
Stefan Farfeleder
faa1ed35ac Document umask's -S option. 2005-08-17 19:44:15 +00:00
Stefan Farfeleder
811beb4b88 Remove a hack for an ancient gdb. 2005-08-15 17:49:38 +00:00
Stefan Farfeleder
711dc65d01 Recent cleanups made it possible to bump WARNS to 3. 2005-08-14 07:46:56 +00:00
Stefan Farfeleder
716b138b4b Put the comparison with PEOF into a new macro is_eof(). Don't use it if the
character comes from a string.
2005-08-13 15:47:13 +00:00
Stefan Farfeleder
adecfb8dfc Declare echocmd() and testcmd(). 2005-08-13 15:04:30 +00:00
Stefan Farfeleder
8d99957008 Use assignment rather than comparison. 2005-08-13 15:00:54 +00:00
Stefan Farfeleder
b37630e3a6 - Provide all initialisers for a struct event.
- Include init.h in the generated init.c.
- Generate prototypes and put the brace on the next line.
2005-08-13 08:38:02 +00:00
Stefan Farfeleder
79ea0bd9f3 First declare the functions to pacify -Wmissing-prototypes. 2005-08-13 08:31:37 +00:00
Stefan Farfeleder
955e9f68da Include missing headers. 2005-08-13 08:26:58 +00:00
Stefan Farfeleder
c789373981 Use prototypes in the MKINIT lines collected by mkinit. 2005-08-13 08:12:18 +00:00
Stefan Farfeleder
bfce4fe8c5 Use prototypes in the generated builtins.{c,h} files. 2005-08-13 08:09:22 +00:00
Stefan Farfeleder
643c91f9ee cvs -d stefanf@ncvs.FreeBSD.org:/home/ncvs 2005-08-13 07:54:23 +00:00
Stefan Farfeleder
7bdc89d779 El_parse's third parameter is now const-qualified, add a cast. 2005-08-11 20:28:26 +00:00
Xin LI
0e3e87bd43 Fix a bug when shell expansion is done against dangling symlinks, by
converting the stat() call to a lstat() call, which will cover the
situation.  One can exercise this bug by referring a dangling link with
something like */the-link.

Approved by:	re (scottl)
Submitted by:	Simon 'corecode' Schubert [corecode fs ei tum de]
Obtained from:	NetBSD via DragonFlyBSD (NetBSD rev. 1.51 and DragonFly
		rev. 1.6)
MFC After:	3 days
2005-07-07 18:10:33 +00:00
Ruslan Ermilov
fb039b55dc Sorted sections and fixed prompt (PS[12]) strings.
Approved by:	re (blanket)
2005-06-14 08:25:00 +00:00
Ruslan Ermilov
fd50df303c Put the description of the -c option in the right place, as
promised by the Argument List Processing section introduction.
What follows the option in the options list is its long name,
not its argument (as is the case for the -c option).  Also
sort references in the SEE ALSO section.

Approved by:	re (blanket)
2005-06-14 07:50:44 +00:00
Garance A Drosehn
01c7bd5378 A second attempt to adjust option-parsing on a shell command, for the
benefit of scripts start out as:     #!/bin/sh -- # -*- perl -*-
With this fix in place, we can commit a change to kern/imgact_shell.c
so FreeBSD will process the `#!' line in shell-scripts in a more
standard fashion.

PR:		16393
Mentioned on:	freebsd-arch
2005-05-16 04:32:41 +00:00
Giorgos Keramidas
38afdcbc3c Various sh(1) enhancements:
- Move the description of the ``-c string'' option closer to the option itself.
- Add an ENVIRONMENT section (1)
- Add more .Xr cross references to the SEE ALSO section.

Obtained from:  NetBSD (1)
2005-04-15 14:53:29 +00:00
Giorgos Keramidas
a762afe578 Use `.Pq Ql'' to quote single characters, instead of `.Pq Li''.
This makes the resulting output more aesthetically pleasing in
text-only terminals:

Reviewed by:	ru
2005-03-04 13:16:50 +00:00
Giorgos Keramidas
91ee1c5df6 Add a section describing the exit status of the shell.
Obtained from:	NetBSD
2005-03-04 12:40:07 +00:00
David E. O'Brien
f0c73601c1 Support \H, \h, \w, \W, \$ string expansion in the prompt.
Submitted by:	mini
2005-03-01 03:35:58 +00:00
Garance A Drosehn
5cc540d471 Change /bin/sh so *it* implements the processing needed for scripts to
work as expected when they have a "shebang line" of:

     #!/bin/sh -- # -*- perl -*- -p

This specific line is recommended in some perl documentation, and I think
I've seen similar lines in documentation for ruby and python.  Those
write-ups expect `sh' to ignore everything after the '--' if the first
thing after the '--' is a '#'.  See chapter 19, "The Command-Line Interface"
in 3rd edition of "Programming Perl", for some discussion of why perl
recommends using this line in some circumstances.

The above line does work on solaris, irix and aix (as three data points),
and it used to work on FreeBSD by means of a similar patch to execve().
However, that change to execve() effected *all* shells (which caused
other problems), and that processing was recently removed.

PR:		16393  (the original request to fix the same issue)
Reviewed by:	freebsd-current (looking at a slightly different patch)
MFC after:	1 week
2005-02-16 05:17:58 +00:00
Warner Losh
9ddb49cbe4 /*- or .\"- or #- to begin license clauses. 2005-01-10 08:39:26 +00:00
Ruslan Ermilov
6fa13ec06f Scheduled mdoc(7) sweep. 2005-01-09 19:54:23 +00:00
Ceri Davies
6b4bbd8a2c Correct typo. 2005-01-04 12:44:25 +00:00
Maxim Konovalov
af5eb6fcc5 o Add a missed "." .
Reviewed by:	ru
MFC after:	3 weeks
2004-12-02 13:13:27 +00:00
Maxim Konovalov
0c77b3c9c1 o Terminate an endless loop sh -T goes into in dowait() around waitproc().
XXX from Tor: "The shell can also go into a similar loop if the child was
killed by signal 127, since the shell would believe the child to have
only stopped (WIFSTOPPED() macro returns nonzero value).  Disallowing
signals 127 and 128 will fix that problem."  See kern/19402 for details.

PR:				bin/66242
Submitted by:			tegge
Analysis and testcase by:	demon
MFC after:			3 weeks
2004-12-02 13:12:43 +00:00
Alfred Perlstein
43d6677ba1 When listing the special $ variables, ($!, $#, etc) list them as $!
instead of just !, this allows one to more easily locate/understand
the section of the manpage in question.

Additional wording correction by: keramida
Reviewed by: keramida
2004-11-01 19:05:04 +00:00
Dag-Erling Smørgrav
bd7667733f Attempting to unset an undefined variable or function should not be
considered an error according to the Open Group Base Specification.

PR:		standards/45738
Submitted by:	Matthias Andree <matthias.andree@web.de>
MFC after:	3 days
2004-09-27 18:43:18 +00:00
Tim J. Robbins
128dc4a2e3 Document missing multibyte character handling in utilities specified
by POSIX.
2004-07-03 02:03:44 +00:00
Ruslan Ermilov
1171aedcdf Deal with double whitespace. 2004-07-03 00:06:28 +00:00
Ruslan Ermilov
eccea571a7 Mechanically kill hard sentence breaks. 2004-07-02 21:04:19 +00:00
Stefan Farfeleder
e0cd241f8b Include <stdio.h> for a sprintf() prototype.
Approved by:	das (mentor)
2004-05-24 10:11:31 +00:00
Brian Feldman
4ad8968a7f Document the "return" built-in better: it will exit . (sources) and
the top-level shell instance, too.
2004-04-14 15:58:50 +00:00
Mark Murray
6195fb4102 Remove clause 3 from the UCB licenses.
OK'ed by:	imp, core
2004-04-06 20:06:54 +00:00
Ruslan Ermilov
4995f06772 Install /bin/sh safely. This allows a shell script to be used
to strip binaries by specifying it in the STRIPBIN environment
variable honoured by install(1).

MFC after:	3 days
2004-03-18 10:55:47 +00:00
Johan Karlsson
c8edef9f48 style.Makefile:
Use WARNS?= instead of WARNS=
2004-02-23 20:05:14 +00:00
Nate Lawson
aa0b7126ba style(9): wrap at 80 columns. 2004-02-12 05:05:56 +00:00
Nate Lawson
97054a769f Handle proper formatting and a buffer overrun when running an old sh on
a system that has sys_nsig > NSIG (i.e. when libc is upgraded.)

Submitted by:	Matt Dillon
Reviewed by:	bde
2004-02-12 05:03:37 +00:00
Ruslan Ermilov
47d7e8a96f Fixed style of DPADD and LDADD assignments as per style.Makefile(5). 2004-02-05 22:44:25 +00:00
Martin Cracauer
e637898ea8 Commit fix sent by Tor Egge <Tor.Egge@cvsup.no.freebsd.org>
Only use return value from system call if system call succeeded.

Tested with `make world` and some of my own scripts.

This should be MFCed soon.  While /bin/sh is hard to test the fix is
obviously correct and can be assumed not to break something else
(famous last words...).
2004-02-05 22:34:05 +00:00
Nate Lawson
1b13752a03 Use sys_nsig instead of NSIG for the length of the signal arrays. This
is important if we add new signals later.  From DragonflyBSD:
jobs.c:1.4, trap.c:1.3.

Obtained from:	DragonflyBSD
2004-01-28 19:01:10 +00:00
Martin Cracauer
6c6fd020de 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.
2004-01-28 18:22:19 +00:00
Dag-Erling Smørgrav
7e1c72660f 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
2004-01-21 12:50:01 +00:00
Ruslan Ermilov
d0123622bb Removed duplicate y.tab.h from SRCS and CLEANFILES. 2004-01-20 13:13:40 +00:00
Maxim Konovalov
8aa55d8126 o Spell 'diretories' correctly.
PR:		misc/60730
Submitted by:	Eugene Grosbein
MFC after:	3 days
2003-12-30 15:39:33 +00:00
Martin Cracauer
bd80d26f3b 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.
2003-12-28 02:05:12 +00:00
Jens Schweikhardt
9e4656f7e8 Do not assume there is only a space between #define and the macro name
when grepping for JOBS. The recent style cleanup replaced the space with
a tab and broke job control detection. Little edits, disastrous consequences.

Submitted by:	Peter Edwards <pmedwards@eircom.net>
X-MFC when:	    in about 5 weeks with the other sh arithmetic fixes.
2003-09-13 06:59:22 +00:00
Ruslan Ermilov
fe08efe680 mdoc(7): Use the new feature of the .In macro. 2003-09-08 19:57:22 +00:00
Jens Schweikhardt
4fe15b85a6 Fix testing of arith_assign() value for $((a=15)).
Submitted by:	Enache Adrian <enache@rdslink.ro>
2003-09-07 10:14:56 +00:00
Tim J. Robbins
94508dc9c8 #include <string.h> for prototypes for strcpy() and strlen().
Submitted by:	Stefan Farfeleder
2003-09-06 16:33:55 +00:00
Jens Schweikhardt
de7112e1ba Style cleanup, mostly
Requested by:	bde
2003-09-04 18:28:42 +00:00
Jens Schweikhardt
bc411549ba Implement missing shell arithmetic operators in $(()) expansion
and variable recognition.

PR:		standards/52972
Submitted by:	Wartan Hachaturow <wart@tepkom.ru>
Reviewed by:	tjr (improved on original patch)
Tested by:	buildworld on CURRENT.
MFC after:	6 weeks
2003-08-30 12:31:44 +00:00
Andrey A. Chernov
508f10f7c1 Remove collate_range_cmp() stabilization, it conflicts with ranges 2003-08-03 04:28:10 +00:00
Diomidis Spinellis
2ba1b30bf5 Changes following CScout analysis:
- Removed dead declarations
- Made objects that should have been declared as static, static.

The changes use STATIC instead of static, following the existing
convention in the rest of the code.

Approved by:	schweikh (mentor)
MFC after:	2 weeks
2003-07-05 15:18:44 +00:00
Bill Fenner
99907703d9 Instead of eating trailing newlines after inserting them into the
output buffer, don't insert them at all.  This prevents a buffer
*underrun* when the substitution consists completely of newlines
(e.g. `echo`) and the byte before the source buffer to which p
points is a '\n', in which case more characters would be removed
from the output buffer than were inserted.

This fixes certain port builds on sparc64.

Approved by:	re (scottl)
Reviewed by:	des, tjr
2003-05-31 06:27:57 +00:00
Ruslan Ermilov
d74e011ff0 mdoc(7) police: A better version of the same.
Approved by:	re (blanket)
2003-05-16 21:19:32 +00:00
David E. O'Brien
8d5c19ffbc Centralize _PATH_* definitions.
Submitted by:	Tim Kientzle <kientzle@acm.org> (embellished by me)
2003-05-05 22:49:23 +00:00
David E. O'Brien
1f156e8160 The is_name and is_in_name macros are FUBAR'ed.
Due to the use of signed vs. unsigned chars on our various platforms, one gets
"warning: comparison is always true due to limited range of data type"
from GCC 3.3.
2003-05-02 06:24:51 +00:00
David E. O'Brien
09a80d4867 Quiet warnings about copyright[]. 2003-05-01 16:58:57 +00:00
Jens Schweikhardt
fbc8f8a2dc Fix references to non-existing or obsoleted man pages.
PR:	docs/51480 (only a small part)
Submitted by:	Diomidis D. Spinellis <dds@aueb.gr>
2003-04-30 19:18:50 +00:00
Tim J. Robbins
e9fa8fddd6 Document the -L and -P options to the cd and pwd commands as being
mutually exclusive. The fact that the most recent one specified on the
command line is the one that takes effect is an implementation detail and
users should not rely on this.
2003-04-12 03:20:28 +00:00
Tim J. Robbins
5821bf03d8 Flush the output buffers before forking a child process to avoid
the child process writing data that the parent should have written.

PR:		50051
MFC after:	2 weeks
2003-03-17 11:28:56 +00:00
Ruslan Ermilov
024ae00499 Fixed (soon might be fatal) -Wformat warnings. 2003-03-15 07:56:59 +00:00
Marcel Moolenaar
caecb2f4c0 Third attempt at removing machdep.h and using ALIGN from <sys/param.h>.
The initial stack_block is staticly allocated and will be aligned
according to the alignment requirements of pointers, which does not
necessarily match the alignment enforced by ALIGN. To solve this a
more involved change is required: remove the static initial stack
and deal with an initial condition of not having a stack at all. This
change is therefore more risky than the previous ones, but unavoidable
(other than not using the platform default alignment).

Discussed with: tjr
Approved and reviewed by: tjr
Tested on: alpha, i386, ia64 and sparc64
2003-02-24 08:07:05 +00:00
Tim J. Robbins
b228ca4dea Revert ALIGN change for the second and last time. I can't figure out
why this is breaking sparc64.
2003-02-18 02:08:20 +00:00
Tim J. Robbins
decb00f677 Second attempt at removing machdep.h and using ALIGN from <sys/param.h>.
The problem with the previous attempt, as noticed by Marcel, was that
stacknxt was being aligned to a pointer boundary instead of an
ALIGNBYTES + 1 boundary, which broke sparc64.
2003-02-17 03:51:44 +00:00
Tim J. Robbins
da5f5439a4 Temporarily back out machdep.h/ALIGN changes. It seems that on sparc64,
using the alignment from sys/param.h (16) instead of the alignment
from machdep.h (8) tickled a nasty bug in the memory allocator that I
haven't been able to track down yet.
2003-02-16 03:28:11 +00:00
Tim J. Robbins
457ae4f0d4 Use the ALIGN macro from <sys/param.h> instead of defining our own
incorrect version in machdep.h. Delete machdep.h.
2003-02-14 23:53:19 +00:00
Philippe Charnier
53a24b9359 Add FBSDID. 2003-02-05 13:23:46 +00:00
Tony Finch
1413f7de53 Improve the layout of the description of the various parameter expansion
modifiers. The paragraph that explains the difference between ${foo:-bar}
and ${foo-bar} etc. was not very visible.
2003-02-03 23:03:05 +00:00
Tim J. Robbins
c57bc2b10e Ensure that the TTY file descriptor is greater than or equal to 10 so that
it doesn't interfere with the user's redirections.

PR:		47136
MFC after:	1 week
2003-01-27 07:41:12 +00:00
Tim J. Robbins
6da31df83b 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
2003-01-21 10:06:04 +00:00
Tim J. Robbins
9c92e72c7f Do not strip CTL* escapes from redirection filenames in exptilde(),
expari(), expbackq() and evalvar(). Similar to revision 1.39.
Patch from Tor Egge.

PR:		45349
MFC after:	2 weeks
2003-01-08 10:50:08 +00:00
Tim J. Robbins
2c25061f18 Add the "wordexp" shell built-in command which will be used to implement
the POSIX wordexp() function.
2002-12-26 14:28:54 +00:00
Ruslan Ermilov
facc67676f mdoc(7) police: Deal with self-xrefs. 2002-12-24 13:41:48 +00:00
Ruslan Ermilov
f5d1157fd1 mdoc(7) police: markup nit. 2002-12-23 15:21:38 +00:00
David Malone
f656dbec97 Use '\033' rather than '\e' as the latter is a gccism.
PR:             46015
Submitted by:   Jeroen Ruigrok van der Werven <asmodai@wxs.nl>
MFC after:      1 week
2002-12-22 21:35:14 +00:00
Tom Rhodes
304199ce19 The code uses trapsasync, however the manual page uses asynctraps. Fix the
manual page to reflect the code.

PR:		45820
Submitted by:	Marco Molteni <molter@tin.it>
Discussed with:	tjr
2002-12-17 20:27:48 +00:00
Tony Finch
162ae3ae7f Document trap EXIT and trap SIGNAME. 2002-12-17 17:31:44 +00:00
Tim J. Robbins
2e3684f843 When job control is disabled, never show the job id when reporting the
status of a background process that has terminated because of a signal.
2002-12-14 01:08:04 +00:00
Ruslan Ermilov
db8993ce9e Capitalize ASCII code names.
Approved by:	re
2002-12-05 08:50:00 +00:00
Tim J. Robbins
0cda444bef Delete worthless comments. 2002-10-30 06:34:52 +00:00
Tim J. Robbins
728b72c237 Avoid accidentally making "-h" a synonym for "fc".
Obtained from:	NetBSD
2002-10-18 10:33:32 +00:00
Tim J. Robbins
c121fd80b8 Do not strip CTL* escapes from redirection filenames in argstr(); they
are later stripped with rmescapes() in expandarg(). If the filename has
already been unescaped, doing it again in rmescapes() can walk off the
end of the string, leading to memory corruption and eventually SIGSEGV.

Noticed by:	kris
2002-10-08 11:22:49 +00:00
Tim J. Robbins
427748f7df Disallow empty condition parts of "if", "while" and "until" compound
commands. Commands like "if then ... fi" and "while do ... done" are no
longer accepted. Bodies of compound commands are still allowed to be
empty, because even though POSIX does not allow them, most shells do.
2002-10-06 06:35:51 +00:00
Tim J. Robbins
54beeb39c2 Use %d in a printf() format string and cast the argument to int instead of
using %td when we know that the number is between 0 and 9; mksyntax is a
build tool and needs to work on -stable.
2002-10-02 09:57:54 +00:00
Tim J. Robbins
658a755b6a Back out experimental changes to fmtstr() that I didn't mean to include
in the previous commit.
2002-10-01 13:41:13 +00:00
Tim J. Robbins
7e73d40ee5 Replace a home-grown printf() clone with a fwopen() wrapper around
libc's vfprintf() that writes to a `struct output' instead of a file.
Inspired by NetBSD's similar changes (they used asprintf() instead).
2002-10-01 13:22:12 +00:00
Maxime Henrion
ca5434bae6 It is now safe to remove WARNS=0 and WFORMAT=0.
Tested on:	alpha, i386, sparc64
2002-10-01 12:12:45 +00:00
Tim J. Robbins
8c39572997 Restore "not found" error message when searching for (or executing)
a program fails because the file or a path component does not exist.

Suggested by:	bde
2002-10-01 11:48:18 +00:00
Maxime Henrion
0c1661b754 - Don't use quad_t when we really mean rlim_t.
- Cast rlim_t to intmax_t when printing it.

This should fix the last format errors in sh(1).

Tested on:	i386, sparc64
2002-10-01 11:44:38 +00:00
Tim J. Robbins
fce40e6ec6 Add back WARNS=0 and WFORMAT=0; gcc is finding nonexistent format string
errors with %qd formats.
2002-10-01 08:55:28 +00:00
Maxime Henrion
ec65e9977a Use the %t format modifier to print differences between
pointers.  This fixes two format warnings on 64 bits
archs which are fatal now that WFORMAT=0 has been removed.

It doesn't fully fix the sh(1) build on 64 bits platforms
though, there is still some quad_t issues that need to be
fixed.

Tested on:	i386, sparc64
2002-10-01 08:40:07 +00:00
Tim J. Robbins
b7f23f5be5 Remove WARNS=0 and WFORMAT=0. The shell compiles cleanly at WARNS=2
on at least i386. If there are warnings on other archs, I'd rather hear
about them than pretend they didn't exist.
2002-10-01 07:26:35 +00:00
Tim J. Robbins
c515abc535 Remove some kind of profiling support that required the 4.2BSD monitor()
function in libc.
2002-10-01 01:30:33 +00:00
Tim J. Robbins
b1a667509b Remove bits and pieces of support for atty, which was made obsolete by
adding history and vi/emacs-style line editing to the shell itself.
Atty was a user-mode terminal emulator (like screen and window) that did
line editing and history.
2002-10-01 00:54:14 +00:00
Tim J. Robbins
abe2dc6158 Callers of error() don't need to supply a program name prefix in the
error message. Stops ulimit giving error messages like "ulimit: ulimit: xyz".
2002-09-30 13:29:32 +00:00
Tim J. Robbins
f7a9b7fe3a Allow a left parenthesis before patterns in case blocks. POSIX requires
us to accept this, but I've never seen a script that uses it.
2002-09-30 13:25:00 +00:00
Tim J. Robbins
e00e16ad7f Allow empty case/esac statements; POSIX requires this, and recent versions
of autoconf are generating scripts that use this feature.

PR:		43275 35879
Submitted by:	Dan Nelson <dnelson@allantgroup.com>
2002-09-30 10:57:44 +00:00
Tim J. Robbins
9a7cafd9b8 Remove dead code which supported systems without O_APPEND, O_CREAT or SIGTSTP. 2002-09-29 12:38:25 +00:00
Tim J. Robbins
1c59560de9 Convert the remaining callers of errmsg() to use strerror(), and remove
errmsg() and its table of error messages.
2002-09-29 11:37:39 +00:00
Jacques Vidrine
dde97b32ff Correct a usage of fnctl that could not be right and results in a
no-op.  I assume it was meant that the close-on-exec flag be set here.
2002-09-11 16:38:33 +00:00
Giorgos Keramidas
d1d578b2cd Add <stdlib.h> to get a prototype for exit().
Reviewed by:	tjr
2002-08-29 14:26:49 +00:00
Philippe Charnier
0d9f1a69d8 Replace various spellings with FALLTHROUGH which is lint()able 2002-08-25 13:01:47 +00:00
Tim J. Robbins
df9e587beb There is a built-in command called "builtin"; spell its name correctly
after rev. 1.77 called it "built-in".
2002-08-24 12:41:23 +00:00
Tim J. Robbins
488edd5bd3 Don't show the process ID of background jobs that have terminated,
for consistency with ksh.
2002-08-24 07:19:01 +00:00
Tom Rhodes
7d971bbf29 s/filesystem/file system/ as discussed on -developers 2002-08-21 17:32:44 +00:00
Jens Schweikhardt
8eed22b1a6 Fix a few typos, among them s/builtin/built-in/ (except for the ref
to the builtin(1) man page.) This is for consistency with the spelling
both proposed by ispell as well as IEEE Std 1003.1-2001.

MFC after:	3 days
2002-08-21 15:05:55 +00:00
Tim J. Robbins
4f8fa749f0 Avoid accessing the current job's process table in the child part of
forkshell() after it has been freed. This caused mysterious behaviour
when anything but the first command in a pipeline tried to access the
terminal when the `junk' malloc() option was enabled (which is the default).
2002-08-18 06:43:44 +00:00
Tim J. Robbins
6c56d93528 Show job control ID, command text, etc. when foreground processes are
suspended. This is a followup to rev. 1.51.

MFC after:	1 week
2002-08-17 13:57:47 +00:00
Tim J. Robbins
d8d737d751 Allow redirections by themselves between "&&" and "||" operators.
For example, >/dev/null && echo foo

Pointed out by:	FUJISHIMA Satsuki
MFC after:	1 week
2002-08-11 03:04:23 +00:00
Ruslan Ermilov
9ba31ca074 mdoc(7) police: tidying. 2002-08-09 10:59:20 +00:00
Tim J. Robbins
7e1975c2b2 Add a -P/-o physical option which behaves similarly to bash/ksh's options
by the same name. This option makes the cd and pwd builtins behave physically
(as opposed to logically) by default.

Submitted by:	fanf
2002-07-25 10:57:39 +00:00
Tim J. Robbins
050f7913c9 Set opterr to zero to avoid duplicate warnings from getopt(3) for unknown
options.
2002-07-25 10:47:38 +00:00
Tim J. Robbins
93c0dc5ea6 Use PATH_MAX instead of a local guess at it, which happened to be incorrect.
Suggested by:	fanf
2002-07-25 09:56:08 +00:00
Tim J. Robbins
b5ae692823 pwdcmd()'s argc and argv arguments are no longer unused, remove __unused.
Pointed out by:	fanf
2002-07-25 09:46:31 +00:00
Tim J. Robbins
be58cc483e Avoid calling el_resize() from a signal handler, even though libedit
itself does that if you set EL_SIGNAL. Instead, set a flag and check it
before calling el_gets(). This is safer, but slower to respond to changes.

Pointed out by:	mp
2002-07-24 02:06:07 +00:00
Tim J. Robbins
9de7305e58 Catch SIGWINCH in interactive shells and call el_resize() to update
libedit's idea of the window size.
2002-07-23 15:05:00 +00:00
Tim J. Robbins
ecd807fb6d Call el_source() to read the contents of .editrc when line editing is enabled.
Obtained from:	NetBSD
MFC after:	2 weeks
2002-07-23 12:26:34 +00:00
Tim J. Robbins
088acf9001 Add a `bind' builtin command, which is simply a wrapper around libedit's
builtin command of the same name. This allows the key bindings for the
shell's line editor to be changed.

MFC after:	2 weeks
2002-07-23 11:50:53 +00:00
Tim J. Robbins
776600e6de Don't allow "||" or "&&" to be the first tokens of a command.
PR:		40386
MFC after:	2 weeks
2002-07-22 05:50:12 +00:00
Tim J. Robbins
2babaf74b5 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'.
2002-07-21 06:49:14 +00:00
Tim J. Robbins
558175ca15 Document that only one of the -n and -e options may be specified for
sh(1)'s echo(1) builtin command.

PR:		32935, 40747
MFC after:	1 week
2002-07-20 04:39:23 +00:00
Tim J. Robbins
2628ebdbd1 Remove broken and incomplete support for old releases of System V,
don't support system that implement getcwd(3) with a pipe to /bin/pwd.
2002-07-19 08:09:04 +00:00
Tim J. Robbins
5b99fa0514 Don't assume file descriptors fit in a short, use an int instead. 2002-07-18 12:24:35 +00:00
Tim J. Robbins
b80be28218 Avoid using ints or shorts to store process id's, use pid_t instead.
The pgrp member of struct job was declared as a short and could not store
every possible process group ID value, the rest of them were benign because
pid_t happens to be an int.
2002-07-18 10:22:42 +00:00
Tim J. Robbins
f1ae2c66c8 Make the message that is printed when the foreground process is terminated
by a signal the same as pdksh/bash/sh before rev. 1.34.
2002-07-18 09:37:51 +00:00
Tim J. Robbins
6c8bbe749e Don't assume the shell's controlling terminal is attached to file descriptor
2. Instead, open /dev/tty. This problem stopped commands in subshells from
being executed correctly if standard error was redirected.

PR:		36671
Obtained from:	NetBSD (but simplified)
2002-07-11 06:42:11 +00:00
Tim J. Robbins
17f08ec1bc Remove support for the "old" tty driver by unifdef -UOLD_TTY_DRIVER;
many other parts of the shell are no longer compatible with this, and it
makes jobs.c quite cluttered with #ifdef's.
2002-07-11 06:26:48 +00:00
Tim J. Robbins
0d3d4c12c3 When growing the job table, don't relocate the jobmru pointer if it's NULL. 2002-07-11 04:22:41 +00:00
Tim J. Robbins
ce80ed021f Close file descriptors when [n]>&- and [n]<&- redirections are used.
This was broken by rev. 1.16.

PR:		40334
MFC after:	1 week
2002-07-09 08:55:46 +00:00
Tim J. Robbins
907354479f Print out commands with NTOFD/NFROMFD redirections that close the
descriptors (">&-" or similar) correctly in the jobs(1) command.
2002-07-09 03:26:47 +00:00
Matthew Dillon
2d41ef4b59 Fix type-o in last commit in preparation for MFC. 2002-07-02 19:06:33 +00:00
David E. O'Brien
2749b14129 Consistently use FBSDID 2002-06-30 05:15:05 +00:00
Sheldon Hearn
62df9b6286 Document addition of RLIMIT_VMEM support, added in rev 1.26 of miscbltin.c. 2002-06-27 16:56:45 +00:00
Matthew Dillon
085b9f3eb2 Add support for RLIMIT_VMEM. The #ifdef's were already there but getopt()
needed to be adjusted.
2002-06-26 00:29:53 +00:00
Juli Mallett
4e17884ffe Remove two unused variables. 2002-06-20 05:21:43 +00:00
Juli Mallett
8b7808bc49 Minor const cleanup.
Don't discard qualifiers we don't need to discard.
2002-06-20 05:20:50 +00:00
Tim J. Robbins
029c8ee4fa Bring documentation on CDPATH and its effects on cd(1) back into sync with
reality (and POSIX): current directory isn't searched unless CDPATH has
a "." element or is unset.

PR:		38442
Submitted by:	oleg dashevskii <be9@be9.ru>
MFC after:	1 week
2002-06-19 12:04:22 +00:00
Tim J. Robbins
83952a118b Don't list shell builtins when the hash command is used (SUSv3) 2002-06-13 07:50:50 +00:00
Tim J. Robbins
8b34ad92a2 Document the -f and -v options of the unset builtin. 2002-06-06 04:12:50 +00:00
Tim J. Robbins
592588448e Quote the output of the no-argument form of the `set' builtin for re-input
to the shell.
2002-06-06 04:02:50 +00:00
Tim J. Robbins
45086f8cf6 Add the SUSv3 -p ("portable") option to both the export and readonly
builtins. This makes export/readonly print lines in the form
"export name=value".
2002-06-06 03:57:22 +00:00
Tim J. Robbins
dee75cf75d Don't modify output that is to be quoted if it contains no IFS characters
or shell metacharacters.
2002-06-06 03:29:23 +00:00
Tim J. Robbins
5b96a60711 Display job status correctly when a pipeline is suspended. 2002-06-04 15:26:00 +00:00
Tim J. Robbins
5179c2f25f Describe finished jobs as "Done", not "Exit" (SUSv3) 2002-06-04 14:40:33 +00:00
Tim J. Robbins
cb1a4fb419 Don't output state' and current' fields for processes that aren't
leaders in -l option to jobs(1).
2002-06-04 14:37:13 +00:00
Tim J. Robbins
d982b3a5f6 Missing prototypes from previous commit. 2002-06-04 13:13:54 +00:00
Tim J. Robbins
41d09fe083 Correct minor spacing problem in output of jobs -l for pipelines. 2002-06-04 13:01:51 +00:00
Tim J. Robbins
e5341cbb17 Quote alias values in the output of the alias(1) builtin so they are
suitable for re-input to the shell (SUSv3)
2002-06-04 12:59:12 +00:00
Tim J. Robbins
ee6712f2f9 Fix typo causing ``fc -e'' to not work correctly. getopt() sets optarg,
not shoptarg.
2002-06-02 08:34:09 +00:00
Tim J. Robbins
32c077867c Adding an entry to the history with H_ENTER moves libedit's internal
history cursor. Reset the cursor after adding the entry to the history
when doing ``fc -s'' so the output is correct.
2002-06-02 08:27:04 +00:00
Tim J. Robbins
39dccc6f6d Implement $PPID, the parent process ID of the shell. 2002-06-01 02:14:48 +00:00
Tim J. Robbins
f63d6dbfc9 Support the remaining job ID formats required by SUSv3:
%+ (current job, same as %%),
%- (previous job),
%?str (job with "str" in its command name).
2002-06-01 01:51:42 +00:00
Tim J. Robbins
ad8a075902 Add -s (output PID's only) and -l (show PID's) options to the jobs(1)
builtin. Modify the output format to match what SUSv3 requires.
2002-05-31 14:04:23 +00:00
Tim J. Robbins
bdfc15df5e #if JOBS around a job control-related statement to allow compilation with
job control disabled.
2002-05-31 13:10:38 +00:00
Tim J. Robbins
e3f3094912 Break the code to display status info for one job out from showjobs() into
showjob(), use it inside dowait() to display status info for consistency,
and in a format closer to what the standard requires.
2002-05-31 13:07:05 +00:00
Tim J. Robbins
3771ef59ae Move job to front of most recently used job list when bg'd or fg'd. 2002-05-31 12:35:34 +00:00
Tim J. Robbins
d86825beb8 Instead of keeping just the jobid of the most recently bg'd or fg'd job,
keep a linked list of the jobs, most recently used first. This is required
to support the idea of `previous job', and to allow the jobs fg and bg
default to be correct according to POSIX.
2002-05-31 12:31:23 +00:00
Ruslan Ermilov
81e9cda2c9 mdoc(7) police: tidy up the markup a bit. 2002-05-29 15:38:59 +00:00
Tim J. Robbins
fc482908be sh appeared in Version 1, not System V.1. 2002-05-25 12:18:27 +00:00
Tim J. Robbins
d513af6a66 Implement `set +o', which displays the currently set options in a format
suitable for re-input into the shell.
2002-05-25 12:11:58 +00:00
Tim J. Robbins
09086b0499 Bring back the cd -L and -P options from revision 1.24, but try harder not
to fail when the logical current directory no longer exists. Allow changes
to absolute paths when logical cwd is invalid, fall back to physical cd
if logical cd fails.
2002-05-22 05:15:53 +00:00
Tim J. Robbins
baf3e7c14b Temporarily back out revision 1.24; it seems to handle the case where the
current directory no longer exists incorrectly and breaks `make cleandir'.
2002-05-22 03:29:20 +00:00
Tim J. Robbins
178897f127 Add the SUSv3 -L and -P options to the cd and pwd builtin utilities. `Logical'
handling of .. is now the default.
2002-05-20 07:54:39 +00:00
Juli Mallett
9e3bfadea8 Remove a small, annoying, nit I ran in to editing this file, a lone tab
on a line by itself.
2002-05-19 17:50:23 +00:00
Tim J. Robbins
1b5a48ff88 Implement the -u (-o nounset) option, which gives an error message if
an unset variable is expanded.

Obtained from:	NetBSD (bjh21, christos)
2002-05-19 08:30:16 +00:00
Tim J. Robbins
addcdbb29f Make the fg and bg commands give the output required by SUSv3.
fg outputs the name of the command, bg outputs the name of the command
and the job id.
2002-05-19 07:27:26 +00:00
Tim J. Robbins
1a958c6653 Implement the -C (-o noclobber) option, which prevents existing regular
files from being overwritten by shell redirection.
2002-05-19 06:03:05 +00:00
Tom Rhodes
ebd4324457 Consistancy check s/file system/filesystem/
Reviewed by:	brian
2002-05-16 01:57:20 +00:00
Dag-Erling Smørgrav
d397408818 Usage style sweep: spell "usage" with a small 'u'.
Also change one case of blatant __progname abuse (several more remain)
This commit does not touch anything in src/{contrib,crypto,gnu}/.
2002-04-22 13:44:47 +00:00
Philippe Charnier
e004acc891 Use `The .Nm utility' 2002-04-16 20:08:06 +00:00
George C A Reid
4c7e4a544a Stop a null pointer dereference in the builtin hash function.
PR:		36141
Approved by:	cracauer
MFC after:	1 week
2002-04-15 15:49:30 +00:00
Warner Losh
1a24391866 Remove now-obsolete __STDC__ ifdefs, remove redundant NULL definition and
include stdlib.h for NULL.
2002-02-18 06:08:23 +00:00
Kris Kennaway
afe781faa2 Lock down with WFORMAT=1 except those directories with unfixed warnings.
Tested on i386 and alpha.
2002-02-04 02:49:19 +00:00
Warner Losh
90e41fc40a %.* takes an int, not a size_t. 2002-02-02 07:06:58 +00:00
Warner Losh
5134c3f799 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)
	{
	...
2002-02-02 06:50:57 +00:00
Sergey Babkin
63f901ef53 The fix for >/dev/stdout, including Tor Egge's fix for the bug in the
original attempt of the fix. And yes, this time I've tried to build
world with it and it succeeded.

Submitted by:	Tor Egge
MFC after: 1 week
2002-01-13 14:37:40 +00:00
Alfred Perlstein
8f5c93f79f backout rev 1.14, it's breaking things. 2001-12-24 22:27:04 +00:00
Sergey Babkin
41f1be05da Added ability to do ">/dev/stdout". The apsfilter people are anxious
to get it MFCed in time for release 4.5.

MFC after: 2 weeks
2001-12-22 02:40:58 +00:00
David E. O'Brien
a748290789 Default to WARNS=2. Binary builds that cannot handle this must explicitly
set WARNS=0.

Reviewed by:	mike
2001-12-04 01:57:47 +00:00
Akinori MUSHA
018d9f6237 Remove the printf builtin command from sh(1), which command is not
used so often that it's worth keeping it as a builtin.

Now that all the printf invocations from within the system startup
scripts, we can safely remove it.

Urged by:	sheldonh  :)

No MFC is planned so far because it may break compatibility and
violate POLA.
2001-11-20 18:33:59 +00:00
Akinori MUSHA
d90c5c4ab4 Make test(1) a builtin command of our sh(1) for efficiency. The
binary size increase is 3,784 bytes (about 0.6%).

I don't drop the printf builtin while I'm here because some /etc/rc.*
scripts seem to use it before mounting /usr where printf(1) resides.

Reviewed by:	arch (sheldonh)
Inspired by:	NetBSD, ksh
Clued by:	ume (on how the printf builtin is used)
2001-11-17 19:10:11 +00:00
Tor Egge
f14c1c47f9 Don't call setvar() with the VTEXTFIXED flag. A copy is created by
setvar() and passed to setvareq(). When the VTEXTFIXED flag is set,
that copy is never freed, causing a memory leak.

PR:		31533
Submitted by:	maxim@macomnet.ru
2001-11-07 23:00:05 +00:00
Tor Egge
c4c8394066 Repair normally unused is_digit() macro. 2001-10-14 21:11:33 +00:00
David E. O'Brien
757eeda04b *** empty log message *** 2001-10-01 08:43:58 +00:00
Tor Egge
d2653b8806 Don't check uninitialized memory for having the shell control character
value CTLARI since this might break expansion of arithmetic expressions.

Don't access memory below start of stackblock.

Problem analyzed by hunt@iprg.nokia.com, slightly different patch applied.

PR:		24443
Submitted by:	hunt@iprg.nokia.com
2001-09-19 20:16:38 +00:00
Tor Egge
0c4eedda7b BASESYNTAX, DQSYNTAX, SQSYNTAX and ARISYNTAX handles negative indexes.
Allow those to be used to properly quote characters in the shell
control character range.
2001-09-19 20:07:47 +00:00
Tor Egge
5f2359b374 Adjust some type checks to include CTLQUOTEMARK in the range of
shell control characters.
2001-09-19 19:58:09 +00:00
Peter Wemm
ef15bfc59f Initialize infp at main() 2001-08-13 21:55:04 +00:00
Ruslan Ermilov
8af1452cf8 Removed duplicate VCS ID tags, as per style(9). 2001-08-13 14:06:34 +00:00
Sheldon Hearn
42abf713c9 can not -> cannot 2001-08-08 18:32:06 +00:00
Ruslan Ermilov
c4d9468ea0 mdoc(7) police:
Avoid using parenthesis enclosure macros (.Pq and .Po/.Pc) with plain text.
Not only this slows down the mdoc(7) processing significantly, but it also
has an undesired (in this case) effect of disabling hyphenation within the
entire enclosed block.
2001-08-07 15:48:51 +00:00
Sheldon Hearn
e1b4d8d074 Use STD{ERR,IN,OUT}_FILENO instead of their numeric values. The
definitions are more readable, and it's possible that they're
more portable to pathalogical platforms.

Submitted by:   David Hill <david@phobia.ms>
2001-07-26 11:02:39 +00:00
Sheldon Hearn
71337c33bd Break the list of parameter expansions into two lists so that
the paragraph introducing the prefix and suffix pattern expansions
does not appear as part of the explanation for the string length
expansion.
2001-07-23 10:18:05 +00:00
Dima Dorfman
7ebcc426ef Remove whitespace at EOL. 2001-07-15 07:53:42 +00:00
Ruslan Ermilov
caa2db3be9 mdoc(7) police: removed HISTORY info from the .Os call. 2001-07-10 10:04:09 +00:00
Ruslan Ermilov
5521ff5a4d mdoc(7) police: sort SEE ALSO xrefs (sort -b -f +2 -3 +1 -2). 2001-07-06 16:46:48 +00:00