Commit Graph

127 Commits

Author SHA1 Message Date
Denys Vlasenko
1b7a9b68d0 hush: fix handling of \^C and "^C"
function                                             old     new   delta
parse_stream                                        2238    2252     +14
encode_string                                        243     256     +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 27/0)               Total: 27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2021-06-15 16:46:30 +02:00
Denys Vlasenko
cad20ced86 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 19:08:16 +01:00
Denys Vlasenko
1237d627e9 hush: fix this case: echo "SCRIPT" | hush
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-12-25 19:01:49 +01:00
Denys Vlasenko
e16f7eb596 hush: output bash-compat killing signal names
This significantly syncronises ash-signals and hush-signals tests.

function                                             old     new   delta
process_wait_result                                  449     450      +1

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-10-24 04:26:43 +02:00
Denys Vlasenko
d4dd48f294 shell: add testsuite for "wait $pid" waiting for other tasks
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-09-29 22:36:36 +02:00
Denys Vlasenko
9aa751b08a shells: fix exitcode_trapN tests to avoid races
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-26 09:05:52 +01:00
Denys Vlasenko
3ced804e31 hush: make "exit" in trap use pre-trap exitcode - fix for nested trap
function                                             old     new   delta
check_and_run_traps                                  276     278      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-21 02:55:53 +01:00
Denys Vlasenko
bb095f4838 hush: implement "return NUM in trap sets $? after trap"
function                                             old     new   delta
builtin_return                                        47      67     +20
check_and_run_traps                                  243     259     +16
run_pipe                                            1583    1597     +14
hush_main                                           1076    1086     +10
run_list                                            1054    1055      +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/0 up/down: 61/0)               Total: 61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-20 16:37:59 +01:00
Denys Vlasenko
c91950f315 ash,hush: testcase for "exit" without arguments in a trap
hush fails this one

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2020-02-19 12:10:41 +01:00
Denys Vlasenko
63d765e666 shells: add tests for backslashes in export VAR=VAL
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-14 19:15:20 +02:00
Denys Vlasenko
9abf53beb4 ash: eval: Variable assignments on functions are no longer persistent
Upstream commit:

    Date: Wed, 4 Apr 2018 17:54:01 +0800
    eval: Variable assignments on functions are no longer persistent

    Dirk Fieldhouse <fieldhouse@gmx.net> wrote:
    > In POSIX.1-2017 ("simultaneously IEEE Std 1003.1™-2017 and The Open
    > Group Technical Standard Base Specifications, Issue 7")
    > <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09>,
    > we read under '2.9.1 Simple Commands'
    >
    > "Variable assignments shall be performed as follows:
    > ...
    > -    If the command name is a standard utility implemented as a function
    > (see XBD Utility), the effect of variable assignments shall be as if the
    > utility was not implemented as a function.
    > ...
    > -    If the command name is a function that is not a standard utility
    > implemented as a function, variable assignments shall affect the current
    > execution environment during the execution of the function. It is
    > unspecified:
    >
    >     *   Whether or not the variable assignments persist after the
    > completion of the function
    >
    >     *   Whether or not the variables gain the export attribute during
    > the execution of the function
    >
    >     *   Whether or not export attributes gained as a result of the
    > variable assignments persist after the completion of the function (if
    > variable assignments persist after the completion of the function)"

    POSIX used to require the current dash behaviour.  However, you're
    right that this is no longer the case.

    This patch will remove the persistence of the variable assignment.

    I have considered the exporting the variables during the function
    execution but have decided against it because:

    1) It makes the code bigger.
    2) dash has never done this in the past.
    3) You cannot use this portably anyway.

    Reported-by: Dirk Fieldhouse <fieldhouse@gmx.net>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
evalcommand                                         1606    1635     +29
evalcase                                             313     317      +4
evalfun                                              280     268     -12
pushlocalvars                                         48       -     -48
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/1 up/down: 33/-60)            Total: -27 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-08-05 11:14:11 +02:00
Denys Vlasenko
a5db1d7354 hush: fix another case where empty "for" wasn't setting exitcode to 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-07-28 12:42:08 +02:00
Denys Vlasenko
fbf44854a3 hush: support "f() (cmd)" functions
Many other shells support this construct

function                                             old     new   delta
parse_stream                                        2950    3018     +68

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 14:56:52 +02:00
Denys Vlasenko
5fa0505f8a hush: fix "set -e; false || x=1; echo OK"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-04-03 11:21:13 +02:00
Denys Vlasenko
9809a82b59 hush: fix raw ^C handlisg in single-quoted strings
function                                             old     new   delta
parse_stream                                        2719    2754     +35

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-13 19:14:27 +01:00
Denys Vlasenko
6606c519ef hush: add command2.tests from ash tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-12 17:58:20 +01:00
Denys Vlasenko
1f1911239c hush: fix handling of ^C in eval
function                                             old     new   delta
run_list                                            1044    1259    +215
builtin_eval                                          45     126     +81
expand_strvec_to_string                               91       -     -91
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 2/0 up/down: 296/-91)           Total: 205 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 13:17:30 +01:00
Denys Vlasenko
932b9971d0 hush: fix handling of raw ^C in scripts: "echo ^C"
function                                             old     new   delta
expand_vars_to_list                                 1133    1187     +54
parse_stream                                        2690    2719     +29

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-01-11 12:39:48 +01:00
Denys Vlasenko
5b3d2eb327 hush: fix "true | func_with_return" not allowing return.
function                                             old     new   delta
pseudo_exec_argv                                     305     312      +7

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 18:02:28 +02:00
Denys Vlasenko
75481d3634 hush: functions have priority over builtins (!)
function                                             old     new   delta
pseudo_exec_argv                                     291     305     +14
run_pipe                                            1560    1555      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 14/-5)               Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-31 05:27:09 +02:00
Denys Vlasenko
ca50caacad shell: some additions to *sh-misc/* tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-24 18:51:40 +02:00
Denys Vlasenko
9fda609a60 hush: add support for "set -e"
function                                             old     new   delta
run_list                                             978    1046     +68
o_opt_strings                                         24      32      +8
reset_traps_to_defaults                              136     142      +6
pick_sighandler                                       57      60      +3
packed_usage                                       31772   31770      -2
hush_main                                            983     961     -22
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/2 up/down: 85/-24)             Total: 61 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-14 13:36:48 +02:00
Denys Vlasenko
840a4355d0 hush: fix "(sleep 1; exit 3) & sleep 2; echo $?; wait $!; echo $?"
function                                             old     new   delta
process_wait_result                                  414     426     +12
builtin_wait                                         283     291      +8
run_list                                             974     978      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 24/0)               Total: 24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-07 22:56:02 +02:00
Denys Vlasenko
e59591a364 hush: Print error messages on shift -1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 20:12:44 +02:00
Denys Vlasenko
b18b04c8a8 shell: remove duplicate sigint1.tests (another copies are in signals/)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:37:30 +02:00
Denys Vlasenko
cafb2d195d hush: add tickquote1.tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-06 18:31:47 +02:00
Denys Vlasenko
10ad622dc2 Spelling fixes in comments, documentation, tests and examples
By klemens <ka7@github.com>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-17 16:13:32 +02:00
Denys Vlasenko
2b1559056c hush: fix a bug in argv restoration after sourcing a file
if sourced file "shift"ed argvs so that $1 is NULL, restore wasn't done.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-09 08:13:21 +01:00
Ron Yorston
ea7d2f6ec0 ash: fix error code regression
The commit 'ash,hush: set exit code 127 in "sh /does/not/exist" case'
only partly implemented the dash commit '[ERROR] Allow the originator
of EXERROR to set the exit status'.  This resulted in incorrect error
codes for a syntax error:

   $ )
   $ echo $?
   0

or a redirection error for a special builtin:

   $ rm -f xxx
   $ eval cat <xxx
   $ echo $?
   0

Signed-off-by: Ron Yorston <rmy@pobox.com>
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-03 11:18:23 +01:00
Denys Vlasenko
02affb4afd hush: rework "wait %jobspec" to work in non-interactive shells too
Also add tests. wait5.tests so far fails (but works for ash and dash).

function                                             old     new   delta
builtin_wait                                         305     283     -22

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-08 00:59:29 +01:00
Denys Vlasenko
672a55e606 hush: allow { cmd } to not be terminated by semicolon in some cases
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-11-04 18:46:14 +01:00
Denys Vlasenko
7e6753609d hush: fix "wait PID"
It was not properly interruptible, and did not update job status
(the exited processes were still thought of as running).

function                                             old     new   delta
process_wait_result                                    -     453    +453
wait_for_child_or_signal                               -     199    +199
run_list                                             996    1002      +6
checkjobs_and_fg_shell                                41      43      +2
builtin_wait                                         328     215    -113
checkjobs                                            516     142    -374
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/2 up/down: 660/-487)          Total: 173 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-28 21:59:09 +02:00
Denys Vlasenko
c775f829db sh testsuite: add tests for exitcode on failure to exec
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:55:34 +02:00
Denys Vlasenko
9793fc576a hush testsuite: fix another false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:14:26 +02:00
Denys Vlasenko
d3b4e5ec6a hust testsuite: fix a false positive
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:10:20 +02:00
Denys Vlasenko
a62bc80571 ash testsuite: add most of hust tests which pass for ash
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-03 00:06:55 +02:00
Denys Vlasenko
c7a774dde4 sh testsuite: sync ash-misc/source* and hush-misc/source*
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 18:23:14 +02:00
Denys Vlasenko
c4cf542c57 sh testsuite: create hush-redir/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:55:51 +02:00
Denys Vlasenko
1b73f8471a sh testsuite: create hush-heredoc/* and move files around
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:49:46 +02:00
Denys Vlasenko
5d6b8729ed hush testsuite: add many tests from ash testsuite
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-02 17:39:31 +02:00
Denys Vlasenko
a2633aa819 hush: add func6.tests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-10-01 20:12:10 +02:00
Denys Vlasenko
78c9c736ab hush: fix 'eval ""' handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 01:44:17 +02:00
Denys Vlasenko
992e0ff7e9 hush: fix ". EMPTY_LINE" not setting $? to 0
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 01:27:09 +02:00
Denys Vlasenko
928e2a7ef4 ash: [EVAL] Make eval with empty arguments return 0
This is a backport of upstream commit:

    [EVAL] Make eval with empty arguments return 0

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-29 00:30:31 +02:00
Denys Vlasenko
eb17b6f6c9 ash: eval: Return status in eval functions
Backported from dash:

    eval: Return status in eval functions

    The exit status is currently clobbered too early for case statements
    and loops.  This patch fixes it by making the eval functions return
    the current exit status and setting them in one place -- evaltree.

    Harald van Dijk pointed out a number of bugs in the original patch.

function                                             old     new   delta
evalcommand                                         1226    1242     +16
cmdloop                                              383     398     +15
evalfor                                              223     227      +4
evalcase                                             271     275      +4
localcmd                                             348     350      +2
evaltreenr                                           927     928      +1
evaltree                                             927     928      +1
evalsubshell                                         150     151      +1
evalpipe                                             356     357      +1
parse_command                                       1585    1584      -1
evalloop                                             177     164     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 9/2 up/down: 45/-14)             Total: 31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-09-28 19:41:57 +02:00
Denys Vlasenko
aa3576a29b hush: fix "redirects can close script fd" bug
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2016-08-22 19:54:12 +02:00
Denys Vlasenko
bc9bee01f3 hush-misc/func_args1.tests: remove "UNFIXED BUG", it does not fail
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-11-04 14:50:19 +01:00
Denys Vlasenko
112889d706 hush: copy for.tests from ash testsuite
This test passes for hush

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-29 22:37:25 +01:00
Denys Vlasenko
450a367a11 typo fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-10-13 01:49:06 +02:00
Denys Vlasenko
b5be13ccd9 hush: fix a nommu bug where a part of function body is lost if run in a pipe
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2015-09-04 06:22:10 +02:00