-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: implement $SHLVL
and $BASH_SUBSHELL
#251
base: main
Are you sure you want to change the base?
Conversation
Performance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
Thanks for working on closing this gap! One main question for you: what do you think about the idea of lazily computing the value of these variables? I've been toying with the idea of generalizing the way we implement |
Ok, I went back and tried to pull on the idea I mention above ^^^. I still think it's worth pursuing, but I think it's sufficiently complicated not to rush it. I'll do a proper review of the changes in this PR so we can get them in. |
@@ -1182,3 +1194,21 @@ fn parse_string_impl( | |||
tracing::debug!(target: trace_categories::PARSE, "Parsing string as program..."); | |||
parser.parse(true) | |||
} | |||
|
|||
// parse a numeric variable from a string, increment it by 1, then re-export | |||
fn increment_level_var( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell.rs
is already, well, longer than I'd like. Could you turn this into a pub(crate)
helper in variables.rs
or similar?
For what it's worth, it seems more understandable to me to have the default
value expressing the pre-increment default (i.e., 0
here).
@@ -23,3 +23,37 @@ cases: | |||
- name: "Piped subshell usage" | |||
stdin: | | |||
(echo hi) | wc -l | |||
|
|||
- name: "SHLVL subshell" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we need some tests to ensure that SHLVL
will work correctly across process invocations (i.e., nested shells and not just subshells). Thoughts on how to do that? Nested invocation of $0
? Call through bash
in the middle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reubeno I thought about it and created a test using $SHELL but is points to nowhere inside the Oracle. Now, looking at it, I learned about $0
, so I will try using that instead. I'm not sure yet how interactivity works there.
$0
$0
$0 -c 'echo $SHLVL; $0'
Implementation of
$SHLVL
and$BASH_SUBSHELL
variables. https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html.SHLVL
BASH_SUBSHELL
Im not sure how to test
SHLVL
, because it requires starting a new shell inside the test.