Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make $status available in the interactive loop #66

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/es.1
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ The return value of a command is obtained with the construct
.De
.PP
The return value of an external program is its exit status
(which in other shells can be found in special variables such as
(which in other shells must be determined from special variables such as
.Cr $?
or
.Cr $status ),
Expand Down Expand Up @@ -962,6 +962,11 @@ If any element of a list is not equal to
(or the empty string), that list is considered false.
.PP
The return value of an assignment operation is the assigned value.
.PP
The default interactive loop makes the return value of the previous command
available via the
.Cr $status
variable.
.SS "Logical Operators"
There are a number of operators in
.I es
Expand Down
18 changes: 9 additions & 9 deletions initial.es
Original file line number Diff line number Diff line change
Expand Up @@ -624,17 +624,17 @@ if {~ <=$&primitives execfailure} {fn-%exec-failure = $&execfailure}
# to print ``break outside of loop'' errors.
#
# The parsed code is executed only if it is non-empty, because otherwise
# result gets set to zero when it should not be.
# status gets set to zero when it should not be.

fn-%parse = $&parse
fn-%batch-loop = $&batchloop
fn-%is-interactive = $&isinteractive

fn %interactive-loop {
let (result = <=true) {
local (status = <=true) {
catch @ e type msg {
if {~ $e eof} {
return $result
return $status
} {~ $e exit} {
throw $e $type $msg
} {~ $e error} {
Expand All @@ -655,7 +655,7 @@ fn %interactive-loop {
}
let (code = <={%parse $prompt}) {
if {!~ $#code 0} {
result = <={$fn-%dispatch $code}
status = <={$fn-%dispatch $code}
}
}
}
Expand Down Expand Up @@ -739,12 +739,12 @@ max-eval-depth = 640
# is for the parent process. pid is not exported so that even if it
# is set explicitly, the one for a child shell will be correct.
# Signals are not exported, but are inherited, so $signals will be
# initialized properly in child shells. bqstatus is not exported
# because it's almost certainly unrelated to what a child process
# is does. fn-%dispatch is really only important to the current
# interpreter loop.
# initialized properly in child shells. status and bqstatus are not
# exported because it's almost certainly unrelated to what a child process
# does. fn-%dispatch is really only important to the current interpreter
# loop.

noexport = noexport pid signals apid bqstatus fn-%dispatch path home matchexpr
noexport = noexport pid signals apid status bqstatus fn-%dispatch path home matchexpr


#
Expand Down