rakitzis / rc

rc shell -- independent re-implementation for Unix of the Plan 9 shell (from circa 1992)
Other
250 stars 23 forks source link

Failing function does not cause `rc -e` to exit #88

Open borkovic opened 1 year ago

borkovic commented 1 year ago

For bash -e, error in a function causes exit:

$ cat b
echo sub-bash pid: $$
function cd2 {
    if cd "$@"; then
        return 0;
    else
        return 1;
    fi;
}

cd2 /fjfjfjfj
echo After cd2
$ echo $$
5566
$ bash -e < b
sub-bash pid: 33200
bash: line 3: cd: /fjfjfjfj: No such file or directory
$ echo $$
5566
$ 

For rc -e, error in a function does not cause exit (subsequent command false does cause exit):

$ cat r
echo sub-rc pid: $pid
fn cd3 {
    if (cd $*) {
        return 0
    } else {
        return 1
    }
}

cd3 /jfjfjoei
echo After cd3
$ 
$ ../rc -e < r
sub-rc pid: 33238
rc: /jfjfjoei: No such file or directory
After cd3
$

I checked that the status after cd3 /jfjfjoei is correct (1).

borkovic commented 1 year ago

I believe the issue is that builtin b_return calls ssetstatus. Most other builtins call set which in turn calls setstatus.

setstatus and setpipestatus call statprint which checks dashee, but ssetstatus does not call statprint and does not check dashee.