Commit Graph

658 Commits

Author SHA1 Message Date
dholland 744c8edc4b Wrap declaration of a STATIC function that's only conditionally defined
in a suitable ifdef, so things still compile if STATIC is defined as
"static", which is for some reason not the default.

(In the long run STATIC should go away - it might have once been a
portability hack but now definitely serves no purpose.)
2008-10-16 15:31:05 +00:00
dholland e54c6daca4 Remove unused global variables 2008-10-16 14:55:28 +00:00
dholland 0faa1734e3 Use "extern" properly for referencing globals defined in other modules.
Now builds cleanly with -warn-common.
2008-10-16 14:36:40 +00:00
dholland 30a1416240 output.c output.h: expose OUTPUT_ERR (flag for an exposed flags variable)
bltin.h: support ferror()
echo.c: use ferror() to fail on output write errors

Another piece of PR bin/39574.
2008-10-12 01:40:37 +00:00
christos 8c54d84110 Fix here documents that end abruptly without NL before EOF.
(Andy Shevchenko)
2008-08-23 10:05:52 +00:00
lukem 2fe2731d3f Remove the \n and tabs from the __COPYRIGHT() strings. 2008-07-20 00:52:39 +00:00
tron 9cae530b67 Revert revisions 1.91 and 1.92. The POSIX spec about the correct behaviour
is contradictory at best. And these changes seem to cause more problems
that they are worth.
2008-05-26 14:55:17 +00:00
tron 4d6f948f7a Fix two more cases of bad handling of "set -e":
- false && false
- false || false
2008-05-24 22:24:32 +00:00
tron c2987416cd Fix another problem with "set -e": "! true" should terminate the shell. 2008-05-24 19:06:43 +00:00
tron 35fbf8dd7f Port revision 1.44 of "src/bin/sh/eval.c" from FreeBSD to fix PR bin/38584.
Reviewed by Michael van Elst.
2008-05-24 17:12:53 +00:00
martin 3028e483e4 Convert to new 2 clause license 2008-04-29 06:53:00 +00:00
christos 76560beef5 Detect unmatched quotes inside old style command substitution.
echo `"`
2008-04-25 17:32:31 +00:00
apb cd12700971 If SHELL_BUILTIN is defined (as will be the case when building external
builtins such as the printf command), then hide a few declarations.

This allows the shell to build again, fixing a problem with
"error" being declared as a function here, and as a variable in
.../usr.bin/printf/printf.c.
2008-03-29 09:58:00 +00:00
apb d6d9ccc8ad * define SHELL_BUILTIN, which other headers may use to hide some of their
symbols if appropriate.  For example, error.h will use it to hide
  declarations that should not be seen by external builtins such as printf.
* The shell's outfmt() function returns void, but the standard fprintf()
  function returns int.  Similarly for several other functions that are
  redefined via macros in bltin.h.  Add a _RETURN_INT macro to do the
  necessary conversion.
* Delete some declarations that appear in error.h.
* Add comments on some #else/#endif lines.
2008-03-29 09:55:40 +00:00
apb 074a931bf5 Remove trailing ';' in definitions of out1c and out2c macros. 2008-03-29 09:49:52 +00:00
dsl 01709217fc Generate ANSI functions.
Just indent the code by a single tab - no need to compare against the
C program generated version any more.
2008-02-27 21:56:14 +00:00
dsl b63023e666 Change spaces to tabs for consistency with adjacent lines. 2008-02-27 21:55:07 +00:00
matt 4498b1fe25 Fix inconsistent definitions 2008-02-15 17:26:06 +00:00
joerg f04ccd71b4 Set unique mode for the history, so that repeating a command doesn't
spam the history.
2008-02-13 12:57:16 +00:00
msaitoh 899c734b12 Conform to XCU Section 2.8.2 (Exit Status for Commands) 2008-01-21 06:43:03 +00:00
dogcow 90ee124aaf This should have been all on one line anyway - and hey, it fixes my build
issue.
2007-12-18 07:25:00 +00:00
perry 8b0f9554ff convert __attribute__s to applicable cdefs.h macros 2007-12-15 19:44:37 +00:00
lukem bcf893f432 use __RCSID() 2007-12-12 22:55:42 +00:00
christos 2554aff24b PR/36531: Greg A. Woods: another very helpful DEBUG TRACE() call for execve()
failures in /bin/sh
2007-06-24 18:36:23 +00:00
christos 546dff6580 PR/36533: Greg A. Woods: minor doc fixes for sh(1) 2007-06-24 17:57:56 +00:00
dsl 8da3353686 Fix sh -c 'true && ! true | false; echo $?'
Add some more TRACE((...)) calls to aid such debugging.
Fixes PR bin/36435
Clearly no one tried this test when the changes of rev 1.31 and 1.44 were done!
2007-06-07 20:57:59 +00:00
apb faafdc7e21 Document that shell arithmetic now uses intmax_t. Document that
variables in shell arithmetic don't need "$" signs.
2007-03-25 06:56:43 +00:00
apb 1a20cbd95e WARNS=4 2007-03-25 06:30:37 +00:00
apb 91ce988bec Make /bin/sh use intmax_t (instead of int) for arithmetic in $((...)). 2007-03-25 06:29:26 +00:00
rillig 9da5e43f4d Since interpreting ELF binaries as shell scripts is not very useful, and
since the current error message is less than helpful, improve it.
2007-02-15 12:02:59 +00:00
christos 30760cbdc7 PR/35410: Valeriy E. Ushakov: /bin/sh mishandles shell function definitions
with function names that are not plain words
1. remove the escape annotations from the function name.
2. check if the function has a valid name before storing it.
2007-01-13 18:58:26 +00:00
christos a54fe38a0d fix a volatile variable; from Anon Ymous 2006-12-18 00:37:33 +00:00
wiz 5c056f6785 s/apparant/apparent/, from Zafer. 2006-11-24 22:54:47 +00:00
christos 272937609b sprinkle volatile. 2006-10-16 00:36:19 +00:00
christos ab28bede4c Prefix "Syntax Error" with the program name, if the command name is not
available. At least this way we get an idea of what program gives us the
message.
2006-10-04 15:00:38 +00:00
dsl 1719403bf2 Fix typo, update date.
Fixes PR/34472
2006-09-04 20:30:36 +00:00
dsl c58b829dda Set the 'not a parameter' flag when we skip initial whitespace.
Otherwise:
    ./sh -c 'x=" "; for a in $x; do echo a${a}a; done'
is processed as a single empty parameter (instead of no parameters).
Should fix the breakage I introdiced in rev 1.75 and PR/34256 and PR/34254
2006-08-22 18:11:42 +00:00
dsl 413b7762c2 Rework the code changes from revisions 1.69, 1.70 and 1.74 so that the code
behaves correctly.
As far as I can tell, "x$@y" now expands correctly, as does IFS=:; set -$IFS.
Fixes PR/33472 (again) and PR/33956
2006-08-21 21:30:14 +00:00
christos a8b3562160 PR/33775: YAMAMOTO Takashi: /bin/sh doesn't accept "(" before case patterns 2006-06-20 15:57:44 +00:00
dsl 0e765f005a When expanding "$@" add a \0 byte after the last argument (as well as all
the earlier ones) so that a separator is added before it when it is empty.
This wasn't needed before a recent change that chenged the behaviour of
trailing whitespace IFS characters.
Fixed PR/33472
2006-05-20 13:57:27 +00:00
christos e80f354dab Coverity CID 3384: Don't close -1. 2006-05-13 19:47:22 +00:00
mrg 084c052803 quell GCC 4.1 uninitialised variable warnings.
XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
2006-05-10 21:53:14 +00:00
simonb 15dc85722d Make the change for bin/31548 to set $PWD on shell startup non-fatal if
the current directory doesn't exist.
2006-05-04 11:16:53 +00:00
snj a640fe8c43 It's "its." 2006-04-24 19:00:29 +00:00
snj bf5ceaae16 It's "its." 2006-04-24 18:00:53 +00:00
christos da09d1a838 PR/33281: Martin J. Laubach: Prevent core-dump on "echo abc | { }". bash
prints and error and ksh prints nothing. We go the ksh way.
2006-04-18 14:44:05 +00:00
christos 3e359756c9 Coverity CID 620: Remove dead code. 2006-03-18 05:25:56 +00:00
christos f6828859fa Coverity CID 890: Possible NULL pointer deref. 2006-03-18 05:23:08 +00:00
christos 169a269417 Coverity CID 1329: Possible NULL deref. 2006-03-18 05:17:36 +00:00
christos df8cbb182e Coverity CID 2479: Clarify confusion about uninitialized variable in the
presence of setjmp/vfork.
2006-03-17 17:20:47 +00:00
rumble 2174dda221 Handle asprintf failing to allocate. 2006-03-17 14:43:11 +00:00
aymeric d5d0c11532 Make the -s flag of fc work correctly. Ensure that only one command is specified
and ensure that we break out of the loop after executing it.
With the previous code, because the re-executed command was added to the
history, it would think that it still had to execute it, leading to an infinite
loop.

The last thing which differs from ksh is that we get the "fc -s " command into
the history, but this is actually rather a feature in my humble opinion.

To test:
$ echo hello
$ fc -s ec
<infinite loop or correct behaviour>
2006-03-06 00:09:22 +00:00
garbled 6ac601d8c4 Add error printing for ENAMETOOLONG. Partially addresses PR bin/13850 .
The actual bug mentioned in that PR no longer exists, but it does cause:
~~~~~: error 63
Which this fix cleans up.
2006-01-02 19:10:33 +00:00
dsl ea2078818f TOG require that 'set +o' output the options in a form suitable for
restoring them - make it so.
2005-12-13 17:44:18 +00:00
dsl e60beff86b Don't change the name of the directory we are going to 'cd' to just because
we decide to remove a leading "./" when deciding whether to print the name.
Stops 'cd .//tmp' ending up the same as 'cd /tmp'.
Fixes PR/30735
2005-11-26 21:44:43 +00:00
christos 8d6ffce2ad PR/31548: Alexander Rigbo: $PWD not set when shell starts up, before pwd
or cd get executed.
2005-10-10 21:14:42 +00:00
christos c05266af8a fix setmode error handling. 2005-10-01 20:23:54 +00:00
tv 964f98e703 Make slightly more portable without extra conditionals needed:
- Use getpgrp() rather than getpgid(0).
  (getpgrp() is already used elsewhere in this same file.)

- Use waitpid(-1, a, b) rather than wait3(a, b, NULL).
2005-09-30 18:57:55 +00:00
wiz 2ea3362a10 In mdoc, use .Pp for new paragraphs, not .br. 2005-09-10 22:09:43 +00:00
dsl 8c772bc707 Don't apply CDPATH if the the first component of the target is "." or "..".
Fixes PR/30973 and applies the principle of least surprise.
Update documentation to match (including date).
(matches behaviour of pdksh - if not it's documentation)
2005-08-20 21:07:42 +00:00
wiz 980a2652ee Aspell, fix an Xref, drop trailing whitespace. 2005-07-15 22:33:48 +00:00
christos 0df4f0ca31 Only do certain actions when we are trully interactive, not just when we
are connected to a tty:
	1. enable editor
	2. print directory on directory change.
	3. print job messages
2005-07-15 17:49:43 +00:00
christos b0d51313b4 If we have a script and we are interactive, set interactive to 2. This
allows us to run scripts with -i without printing the prompt like the
other shells do.
2005-07-15 17:46:54 +00:00
christos e996b4625d Allow trap to work on ignored signals when the shell is interactive. 2005-07-15 17:23:48 +00:00
christos ab760d2891 make setsig() return sig_t 2005-07-11 02:37:31 +00:00
christos 3564ac65d4 Don't hard ignore signals that were ignored by our environment, because
when we try to set a trap on them it will not work. Also while I am here:
1. don't change the action status if the signal system call failed.
2. don't try to sigignore it if signal failed.
3. clear the signal mask in case our parent blocked it for us.
2005-07-11 02:37:05 +00:00
christos 6310b59691 sprinkle a little const, and now everything compiles with WARNS=3 2005-06-26 19:10:48 +00:00
christos b61c2197f1 Revert part of the previous commit. We cannot fix the problem by not waiting.
The problem is that the subshell code is not doing redirections properly.
2005-06-23 23:05:29 +00:00
christos 306d33d145 Don't wait for a background job in a subshell when we are set to EV_EXIT.
While I am here, call forkshell() explicitly FORK_FOO flags instead of
depending in FORK_FG == 0 and FORK_BG == 1.
2005-06-22 23:32:45 +00:00
lukem 5166671bc3 appease gcc -Wuninitialized 2005-06-01 15:41:19 +00:00
lukem 50cde64b47 Mark temp_path volatile so that it won't get clobbered after longjmp.
(Also appeases gcc -Wuninitialized.)
2005-06-01 15:38:32 +00:00
wiz 24bf3d8ac3 Whitespace and punctuation fixes. 2005-05-24 00:03:52 +00:00
christos c3b8cf7d21 Only add the function when we initialize. Restore the binding of tab to
ed-insert if tabcomplete is cleared.
2005-05-09 11:35:19 +00:00
dsl 82537bf8e8 If 'set -o tabcomplete' it set, then bind <tab> to the libedit filename
completion function.
Note that the libedit code will probably want fine-tuning!
While editing the man page, add a note that non-whitespace IFS chars are
terminators and can generate null arguments.
2005-05-07 19:52:17 +00:00
dsl 3acd9704cb A rather better fix for treating $((x)) as equivalent to $(($x)) provided
that $x has a numeric value - which is what posix/sus needs.
2005-03-21 22:37:09 +00:00
dsl a65ddf9664 Back out previous, amongst other things it breaks $((0x10)) 2005-03-21 20:10:29 +00:00
dsl b747d738fa Treat $((x)) as equivalent to $(($x)) - posix seems to require this now. 2005-03-20 21:39:11 +00:00
dsl aecb1ce456 Add 'continue' as body of empty loop. 2005-03-20 21:38:17 +00:00
dsl 328c436518 Check quoting before merging ifs regions.
sh -c 'set -- a; x="b c"; set -- "$@"$x'
now correctly gives $1=ab, $2=c
2005-03-19 16:38:27 +00:00
dsl 2078d2c0ca Don't merge ifs regions with different quoting requirements 2005-03-19 15:02:58 +00:00
dsl 4803d37f2b Fix the way the 'read' builtin processes IFS. In particular:
- IFS whitespace is now processes correctly,
- Trailing non-whitespace IFS characters are added to the last variable
  iff a subsequent variable would have been assigned a non-null string.
Now passes the 'read' tests in http://www.research.att.com/~gsf/public/ifs.sh
2005-03-19 14:22:50 +00:00
dsl 8693718ba1 Fix printing of invalid commandname after certain types of errors on builtins.
Fixes bug bin/29410 in head.
All of /bin/sh needs pulling up into 2.0
2005-03-02 20:57:31 +00:00
dsl f712e70aee expbackq() was incorrectly backing up a temporary buffer when removing \n
from the end of output of commands inside $(...) substitutions.
If the program output is n*128+1 bytes long (ending in a \n) then the code
checks buf[-1] for another \n - looking an uninitialised stack.
On a big-endian system an integer of value 10 will satisfy this (unlikely
on little endian) and can happen depending on the last code path to use
a lot of stack!
This caused the problem with newvers.sh on sparc64 after ', 2005' was
added to the date list.
Fixed PR/28852
2005-02-14 20:46:26 +00:00
perry 3fa24d7834 remove obsolete register declarations 2005-02-06 04:43:43 +00:00
christos 2a32d39ed6 PR/28940: David Laight: /bin/sh doesn't quote the output of trap. 2005-01-11 19:38:57 +00:00
christos 027df12dd8 Pass WARNS=3 2004-10-30 19:29:27 +00:00
enami 87aaf3d70d Fix a bug introduced by previous commit. It breaks export command
with multiple arguments if one of them are already set.  Fix PR#27155
and probably PR#27143.
2004-10-06 10:23:43 +00:00
dsl 5f9b910124 Save the length of each variable in the name table so that we can
compare the lengths and then use memcmp() in the search code.
Speeds up one of my scripts by a facter of 2.
Increase the size of the variable hash table.
Cuts down time for script to execute from 60 seconds to 10.
Move variable search into a new function to hide the implementation
from most of the code, new version is slightly smaller than old.
2004-10-02 12:16:53 +00:00
seb cf788c3115 Add new builtin `wordexp' to support wordexp(3).
From FreeBSD.
Provided in PR lib/26123.
Approved by kleink@.
2004-07-13 15:05:59 +00:00
christos 5dd9099216 PR/25699: David Laight: sh(1) hangs opening a named pipe as stdin for
background process
This happens because we vfork, and then open a named pipe with O_RDONLY
and block in the child. We avoid this, by opening the file with O_NONBLOCK,
and then reset it if we are vforked. XXX: this is an ugly fix.
2004-07-08 03:57:33 +00:00
mycroft 1ccdf5daeb Make "set -e" once again provide the behavior documented in the man page,
which was unnecessarily changed in revision 1.50 while fixing other bugs.
That is, exit the shell if the last command in a || or && compound statement
is not short-circuited, and exits with a false status.  I.e., the following
will cause the shell to exit:

  set -e
  false || false

While this is not the prescribed behavior in SUSv3, it is what our man page
documents, and it is what all of the following implementations do:

  NetBSD /bin/ksh (pdksh)
  bash
  zsh
  Solaris 9 /bin/sh
  Solaris 9 /usr/xpg4/bin/sh
  Solaris 9 /usr/bin/ksh
  Tru64 /bin/sh
  HP/UX 11 /bin/sh

The "standard" seems to be wrong in this instance.
2004-06-30 09:32:38 +00:00
dsl 60bb0d96f3 Fix treatment of ' inside a 'here document' with a quoted EOF marker.
Fixes a breakage from the previous version.
2004-06-27 10:27:57 +00:00
dsl c6cbc16d26 Correctly apply IFS to unquoted text in ${x-text}.
Fixes PR/26058 and the 'for i in ${x-a b c}; do ...' and ${x-'a b' c}.
I can't find a PR for the latter problem.
Regression test goind in shortly.
2004-06-26 22:09:49 +00:00
dsl 97e8f81436 Remove a broken optimistion that crept in earlier today. 2004-06-26 20:48:44 +00:00
dsl 8e940884ca Kill a diagnostic I accidentally left in. 2004-06-26 14:21:29 +00:00
dsl e4a2a056d2 No functional changes (intended).
Rename some variables, add some comments, and restructure a little.
In preparation for fixing "set ${x-a b c}" and friends.
2004-06-26 14:09:58 +00:00
dsl 39cf7788fc Use shell variables to get '(' and '\' inside shell substitution patterns.
Solves problems with different shells having differntly buggy parsers
(and the standard probably allowing random behaviour).
Should fix bin/25938
2004-06-15 23:09:54 +00:00
dsl c6e67e3bf2 Change '\0' to 0 so that the SVR4 'echo' doesn't convert it to a null byte.
Fixes bin/25938
2004-06-15 22:57:27 +00:00
christos cf19966782 Undo previous fix, breaks:
#!/bin/sh
echo ${1+"$@"}
./sh.new foo.sh a b c
a b c b c
I'll revisit this when I have some more time.
2004-06-09 12:17:36 +00:00
christos fc5d411571 "for i in ${x-a b c}; do echo $i; done" should print "a\nb\nc\n" not "a b c\n"
like other shells do. mark the expansion for ifs splitting. XXX: linux has a
very complicated fix for this. I wonder why.
2004-06-08 03:29:51 +00:00